Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Replace expensive second babel-traverse pass with fast custom visitor. #1947

Closed
wants to merge 1 commit into from

Conversation

NTillmann
Copy link
Contributor

Release notes: Speeding up Prepack by 22%, saving 8% memory.

This closes #1812.

This completely refactors the ClosureRefReplacer into a new
standalone ResidualFunctionInstantiator.

By avoiding babel-traverse, this visitor implementation is way faster.
Also, it only clones those nodes which are being changes, preserving all others,
insteading of cloning an entire function if any node needs to change; in this way,
memory is saved as well.

On a large internal benchmark (27MB minified JavaScript bundle with 31MB sourcemaps file), this change reduces overall time from 200s down to 157s: 22% faster. This due to savings during serialization, which goes down from 71s to 23s (while making the visitor 6s slower due to additional work).

Also, overall memory usage goes down from 3582MB to 3307MB, a 8% savings. Again, mostly due to savings in serialization, where surviving allocations going down from 337MB to 51MB, while slightly increasing allocations in the visitor.

Release notes: Speeding up Prepack by 22%, saving 8% memory.

This closes #1812.

This completely refactors the `ClosureRefReplacer` into a new
standalone `ResidualFunctionInstantiator`.

By avoiding babel-traverse, this visitor implementation is way faster.
Also, it only clones those nodes which are being changed, preserving all others,
insteading of cloning an entire function just in case any node needs to change;
in this way, memory is saved as well.

On a large internal benchmark, this change reduces overall time from 200s down to 157s: 22% faster. This due to the time savings during serialization, which goes down from 71s to 23s (while making the visitor 6s slower due to additional work).

Also, overall memory usage goes down from 3582MB to 3307MB, a 8% savings. Again, mostly due to savings in serialization, with surviving allocations going down from 337MB to 51MB, while slightly increasing allocations in the visitor by 11MB as it has to store additional data.
Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@trueadm
Copy link
Contributor

trueadm commented May 14, 2018

I know @loganfsmyth and @hzoo might be super busy, but if they could take a look at some of the Babel related code here it might be good to see if there are any further optimizations that we might be able to do to improve performance.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NTillmann is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NTillmann is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@hermanventer hermanventer deleted the Issue1812 branch May 18, 2018 18:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Babel traverse based ClosureRefReplacer
3 participants