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.
We are continuing to see stack overflows in the new parser. This is mainly because the AST type have quite large sizes.
Using the command
cargo +nightly rustc -- -Zprint-type-sizes
, we can find the size of each AST structure.The most expensive struct in terms of size is
NumericFor
:The biggest sizes come from
start
,end
andstep
, which are allExpression
nodes. So Expression has a size of888
bytes.Looking at the size of Expression, we can see the most significant size is used by the
Function
variant, at 888 bytes, whilst the next largest variant is TableConstructor at 304 bytes: a 584 bytes difference:If we Box the anonymous function variant, we will be able to shave off at least 584 bytes on every single Expression node, which can add up to a significant saving. We do that in this PR.
After doing so, the size of
Expression
is now 296 bytes, taken up by the largest variantTableConstructor
.NumericFor
decreases from 3936 bytes to 2160 bytes, a 1176 bytes decrease.The complete type size list are attached for reference
type-sizes-before-change.txt
type-sizes-after-change.txt