Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minification] Add noEmitHelpers, importHelpers and tslib as a dependency #3913

Closed
MSNev opened this issue Jun 14, 2023 · 0 comments · Fixed by #3914
Closed

[Minification] Add noEmitHelpers, importHelpers and tslib as a dependency #3913

MSNev opened this issue Jun 14, 2023 · 0 comments · Fixed by #3914
Assignees
Labels
enhancement New feature or request feature-request

Comments

@MSNev
Copy link
Contributor

MSNev commented Jun 14, 2023

To better support minification of the generated code we need to change the default settings by adding the following to the tsconfg.base.json.

This changed should be applied to ALL generated packages in both the JS and Contrib repo's

    "importHelpers": true,
    "noEmitHelpers": true

And include the relevant version of tslib as a dependency so that during packaging all dependencies can be resolved.

What does this do?

By enabling these settings rather than TypeScript emitting JavaScript code for the "helper" (which are also included in tslib) it will emit code to import tslib. While this does not sound like much by default when TypeScript emits the helper inline this causes multiple instances of the helpers to get included in a bundle (1 for each usage scenario) which results in unnecessary additional duplicate functions.

For some metrics, simply adding these settings to the opentelemetry web sandbox and letting it generate the complete bundles results in the following size reductions, where Raw is the bundle created by Rollup (with tree-shaking) for the package and Min is the minified version of that raw JS file.

Package Current (UMD Module) bytes With Import helpers (UMD Module) bytes Minfied Bundle Saving
@opentelemetry/api Raw: 49,512;  Min: 19,706 Raw:43,570;  Min: 17,612 ~2k
@opentelemetry/core Raw: 97,026; Min: 36,727 Raw: 85,238; Min: 32,383 ~4k
@opentelemetry/sdk-trace-web Raw: 175,118; Min: 66,719 Raw: 152,126; Min: 58,094 ~8k

The bundles generated by the sandbox are self contained and include all of their dependencies (include the single tslib instance).

Additional context

Discussed during the June 14th, 2023 Sig meeting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature-request
Projects
None yet
1 participant