perf(transformer): arrow function transform: reduce stack memory usage#5940
Merged
graphite-app[bot] merged 1 commit intomainfrom Sep 23, 2024
Conversation
This was referenced Sep 20, 2024
Member
Author
CodSpeed Performance ReportMerging #5940 will not alter performanceComparing Summary
|
82874de to
319b9fe
Compare
39ab5a2 to
9807363
Compare
9807363 to
bc11788
Compare
c3e8c58 to
6979aa2
Compare
bc11788 to
1c3b103
Compare
7827028 to
632b462
Compare
1c3b103 to
6671dbb
Compare
6671dbb to
750ef88
Compare
632b462 to
ff7d9c1
Compare
750ef88 to
a98259b
Compare
a98259b to
8cc4b35
Compare
e72ab8c to
882a51d
Compare
8cc4b35 to
0dedf32
Compare
0dedf32 to
5008b88
Compare
e52ff0e to
7085829
Compare
5008b88 to
ca3e3f6
Compare
ca3e3f6 to
8a6b2e5
Compare
8a6b2e5 to
7e76547
Compare
This was referenced Sep 21, 2024
Dunqing
approved these changes
Sep 23, 2024
Member
|
Is |
Contributor
Merge activity
|
#5940) Arrow function transform maintains a stack for blocks which may (or may not) need a `var _this = this;` statement added to them. This stack was `Vec<Option<BoundIdentifier>>` (24 bytes per block). Most blocks won't need a statement added, so most entries are `None`. Introduce an abstraction `SparseStack`. This stores the stack split into 2 arrays. First array is `Vec<bool>` indicating if a statement needs to be added or not. Only if a statement *does* need to be added, then its details are pushed to a separate array `Vec<BoundIdentifier>`. This means the memory taken up by the stack will be roughly 1 byte per block, instead of 24 bytes per block (assuming very few blocks need statements added).
7e76547 to
618e89e
Compare
Dunqing
pushed a commit
that referenced
this pull request
Sep 23, 2024
Optimize `SparseStack` (which was introduced in #5940). Initialize it with a single entry, and ensure the stack is never emptied. This makes `take`, `get_or_init` and `get_mut_or_init` methods infallible, since there is always an entry on the stack to read.
Member
Author
Yes, I was planning to create a "common" transform which holds a |
Boshen
added a commit
that referenced
this pull request
Sep 24, 2024
## [0.30.1] - 2024-09-24 ### Features - 5c323a2 minifier: Loop compressor passes (#6013) (Boshen) ### Bug Fixes - 9ca202a codegen: Preserve newlines between comments (#6014) (Boshen) - 4a99372 codegen: Print jsdoc comments for `TSEnumMember`s (#6007) (camc314) - 97a2c41 isolated-declarations: False positive for class private getter with non-inferrable return type (#5987) (michaelm) ### Performance - 2b17003 linter, prettier, diagnostics: Use `FxHashMap` instead of `std::collections::HashMap` (#5993) (camchenry) - 7b90d79 transformer: `SparseStack` always keep minimum 1 entry (#5962) (overlookmotel) - 28fe80a transformer: Logical assignment operator transform use `SparseStack` (#5960) (overlookmotel) - 9f7d4b7 transformer: Exponentiation operator transform use `SparseStack` (#5959) (overlookmotel) - 5dc0154 transformer: Nullish coalescing operator transform use `SparseStack` (#5942) (overlookmotel) - 618e89e transformer: Arrow function transform: reduce stack memory usage (#5940) (overlookmotel) ### Documentation - 5a0d17c ast: Document more AST nodes (#6000) (DonIsaac) - 18371dd oxc: Include feature-guarded modules in docs.rs (#6012) (DonIsaac) - 1abfe8f semantic: Document `SymbolTable` (#5998) (DonIsaac) - f5eee72 semantic: Correct docs for `Reference` (#5992) (overlookmotel) - 860f108 transformer: Add to arrow functions transform docs (#5989) (overlookmotel) ### Refactor - 0a2f687 minifier: Move dce conditional expression to `RemoveDeadCode` (#5971) (Boshen) - f02bf51 transformer: Arrow function transform: remove unnecessary assertion (#6002) (overlookmotel) --------- Co-authored-by: Boshen <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Arrow function transform maintains a stack for blocks which may (or may not) need a
var _this = this;statement added to them.This stack was
Vec<Option<BoundIdentifier>>(24 bytes per block). Most blocks won't need a statement added, so most entries areNone.Introduce an abstraction
SparseStack. This stores the stack split into 2 arrays. First array isVec<bool>indicating if a statement needs to be added or not. Only if a statement does need to be added, then its details are pushed to a separate arrayVec<BoundIdentifier>.This means the memory taken up by the stack will be roughly 1 byte per block, instead of 24 bytes per block (assuming very few blocks need statements added).