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

Explore mangling exported symbol names #180461

Closed
mjbvz opened this issue Apr 21, 2023 · 4 comments
Closed

Explore mangling exported symbol names #180461

mjbvz opened this issue Apr 21, 2023 · 4 comments
Assignees
Labels
debt Code quality issues
Milestone

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 21, 2023

Follow up on #165429

In #165429, we added managing of private fields in the VS Code codebase, resulting in a nice bundle size reduction

Looking through our shipped sources though, there is still lots of repeated text. One lower hanging branch we could try next is mangling exported functions. The localize function for instance seems to be used around 10000 times in the shipped sources, while as a less extreme case the common array function coalesce appears 100 times

Exported functions are a good candidate because we don't have to worry about them being serialized

With my simple prototype, mangling exported functions names saves an additional 446.412kb on top of the mangled private property names (total size reduction is now 2357.235kb. Size savings will be smaller when the content is served compressed but it's still is a nice "free" size reduction

@mjbvz mjbvz self-assigned this Apr 21, 2023
@mjbvz mjbvz added this to the May 2023 milestone Apr 21, 2023
@mjbvz
Copy link
Collaborator Author

mjbvz commented Apr 21, 2023

From a quick test, only a few patterns in our code seem to be causing issues:

mjbvz added a commit to mjbvz/vscode that referenced this issue Apr 21, 2023
For microsoft#180461

This prototype tries to mangle exported functions, saving a further 440kb from the bundle size
@mjbvz mjbvz added the debt Code quality issues label Apr 24, 2023
mjbvz added a commit to mjbvz/vscode that referenced this issue Apr 25, 2023
For microsoft#180461

This prototype tries to mangle exported functions, saving a further 440kb from the bundle size
@mjbvz
Copy link
Collaborator Author

mjbvz commented Apr 25, 2023

Latest version increases total savings up to 4150 by managing:

  • exported functions
  • exported consts, including shadow service identifiers
  • Exported classes

mjbvz added a commit to mjbvz/vscode that referenced this issue May 1, 2023
For microsoft#180461

This prototype tries to mangle exported functions, saving a further 440kb from the bundle size
@mjbvz mjbvz modified the milestones: May 2023, June 2023 May 10, 2023
This was referenced May 19, 2023
@mjbvz
Copy link
Collaborator Author

mjbvz commented May 25, 2023

Targeting June to get this merged

A few follow ups after this initial work is merged:

  • When generating names, ideally we should prioritize giving more used symbols shorter names. This probably isn't a huge win as we don't generate very long names anyways, but for functions like localize that are used thousands of times it would be nice

  • I had to skip mangling localize due to how this function is used across projects and interacts with build scripts

  • I explored mangling enums and enum members (for all non-const enums). This works but generates lots of compile errors with the standaloneEnums and other places where enums are treated as API

@mjbvz mjbvz changed the title Explore mangling exported function names Explore mangling exported symbol names May 25, 2023
mjbvz added a commit that referenced this issue Jun 13, 2023
* Mangle exported functions

For #180461

This prototype tries to mangle exported functions, saving a further 440kb from the bundle size

* Fix missing call

* Also try mangling top level exported consts too

* Fixing errors

* Don't run on build files

* Skip a few more manglings and revert change to namespace

* Skip a few more monaco files

* Also mangle consts that shadow types

This increases savings up to 3325

* Also mangle exported classes

* Skip mangling more localization functions for now

* Opt out pfs

* Update build script

* Run find locations task in parallel

This should speed up compile

* Cleanup before close

* Limit workers to avoid hitting memory limit

* Limit pool size

* Skip one more mangling

* Exclude entrypoints from mangling

* Try to fix web build and clean up code

* Exempt a few more projects

* Exempt another file

* Also exempt html

* Skip mangling ext entrypoints

* Use prefix that can't be confused with rpc calls

* Fix max call stack error

* Switch prefixes

* Don't mangle ambient declarations

* Use correct way of checking modifier flags

* Workaround getCombinedModifierFlags not doing what I'd expect

Maybe needs the checker to be enabled too? Just check parent chain instead for now

* Clean up code and add logic showing how enum mangling could work

* Remove a few more skipMangles

Use entrypoints instead

* Fix entrypoint name
@mjbvz
Copy link
Collaborator Author

mjbvz commented Jun 19, 2023

Fixed by debcf16

@mjbvz mjbvz closed this as completed Jun 20, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues
Projects
None yet
Development

No branches or pull requests

1 participant