Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid traversing the whole tree to normalize pseudo globals
Summary: The `normalizePseudoGlobals` renames the `__d` function params to shorter names, e.g. `$$__REQUIRE` to `r`. The old implementation traversed the whole AST and renamed any existing usages / declarations, e.g. it renamed all existing references to `r`. Traversing the full AST only to rename a potential conflicting declaration is rather expensive. This diff changes the plugin so that it generates a new unique name in case the name for a function argument, e.g. `r` is already used in the module. This is cheaper because it only requires to traverse the AST once to build up the scope. This might arguably result in larger file size in case the function argument (e.g. `require`) is heavily used. However, renaming the existing declaration might also result in larger file sizes if that declaration is heavily used. Overall: The current implementation optimizes for an edge case where one letter variables are used in the program. I would argue that it isn't worth spending many cpu-cycles on this edge case. Win per Worker on an ondemand. {F346854274} Following the result for building MarketplaceHome.entrypoint on my ondemand using a local metronome build with `--reset-cache`. | | Run 1 | Run 2 | Run 3 | |--------|--------|--------|--------| | Before | 1m 14s | 1m 14s | 1m 13s | | After | 1m 11s | 1m 12s | 1m 12s | Reviewed By: cpojer Differential Revision: D25176777 fbshipit-source-id: 49245fa03987e2eb219a9d0dffb690fecb71093b
- Loading branch information
1 parent
279b295
commit 745e2d8
Showing
2 changed files
with
83 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters