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

bundler option to strip comments #2413

Closed
turadg opened this issue Aug 16, 2024 · 2 comments · Fixed by #2420
Closed

bundler option to strip comments #2413

turadg opened this issue Aug 16, 2024 · 2 comments · Fixed by #2420
Labels
enhancement New feature or request

Comments

@turadg
Copy link
Member

turadg commented Aug 16, 2024

What is the Problem Being Solved?

Endo is often bundled for use in runtime environments that constrain bundle size. Sometimes these bundles exceed the limits (e.g. Agoric/agoric-sdk#9900).

A significant source of bytes is comments. If comment could be stripped at the discretion of the builder of the bundle, that would reduce the size significantly.

E.g. in a recent contract bundle the patternMatchers.js file was 59KB. That’s a little less than the raw 62KB of the source in Endo
but still quite a lot more than it would be without comments. Terser with defaults drops it to 19KB. If we cut Endo dep size to 1/3 or even 2/3 we’d buy a lot more time on bundle size limits.

Description of the Design

Provide an option to the bundle-source command to turn comments to whitespace.

It should preserve line numbers so that stack traces in runtime match up with the original source code. However it does not need to preserve character positions per line.

Unlike conventional minifiers, it should not perform any alterations to the actual code,

While implementing this, it may be helpful to consider how one would extend it to

Security Considerations

Stripping comments can make it harder to audit the bundled code. But conversely, comments can mislead in an audit.

Given the complexities of audits and the trade-offs with runtime constraints, solving auditing will require purpose-built tooling: #1656

Scaling Considerations

Test Plan

Compatibility Considerations

Upgrade Considerations

@mhofman
Copy link
Contributor

mhofman commented Aug 19, 2024

Provide an option to the bundle-source command to turn comments to whitespace.

Quick note that striping comments requires in some case to insert a semi colon to preserve the semantics of ASI. It's not always purely replacing with whitespace.

@kriskowal
Copy link
Member

My intention is to replace the interior of comments: erase all characters before newlines, replace all characters on the final line with spaces, preserve all newlines. That covers @gibson042’s subtle case of comments containing newlines serving as newlines for ASI.

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

Successfully merging a pull request may close this issue.

3 participants