Skip to content

Use abbreviations for common JS symbols to save on code size #20701

@sbc100

Description

@sbc100

I notices that there are cases where use common JavaScript symbols (e.g. Object.assign) multiple times in a single program and non of our current minification passes (including closure compiler) are able to remove or reduce the duplication of these strings.

Admittedly, gzip will can probably do a good job here, but we can't fully depend on that.

I tried creating simple change where I add common abbreviations to shell.js e.g.:

var assign = Object.assign;
..etc

However this has some downsides. Notably:

  • It always includes these even if they are not used. We cannot use library dependencies here because some of the usages are in the shell itself which comes before any library symbol is included.
  • The usages would all need to be changed from some thing well-known to something not well-known. This decreases maintainability and makes debugging harder. It also means that user-code that uses these symbols would need to be updated too or would not benefit.

Proposed solution: Add a new acorn optimizer pass that can find all the usages of these symbols and inject the abbreviations in the right place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions