Repository navigation
rc: a spread given to a rest parameter is held across the call and given back (Array.join leak) - #924
Merged
Merged
Conversation
…ven back `f(...xs)` packs a new array with a spread of run-time length: an empty CreateArray filled through a slot of its own, read out with a `ts.Load`. OwnedReturnConsumptionPass holds a new array given straight to a call (retain before, release after) only when it comes from CreateArray/NewArray, so this one - born uncounted, holding a count of every element - was never given back. The default library's Array.join ends in `"".concat(...parts)`: 1M joins of two strings grew to 36.6 MB at 300K; now flat at 5.7 MB. MLIRGen marks the literal's final read __spread_array_literal (SPREAD_ARRAY_LITERAL_ATTR_NAME), and the pass counts it as a new array under rc. Own keeps its own handling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Fixes an
-mm=rcleak behindArray.join: a spread of run-time length passed to a rest parameter (f(...xs)) packs a temporary array that was never released.Cause. MLIRGen builds that array as an empty
ts.CreateArray, fills it through a slot of its own, and passes on ats.Loadof the slot. OwnedReturnConsumptionPass holds a new array across a call (retain before, release after) only when it comes straight fromCreateArray/NewArray. So this array, born at count 0 and holding a count of each element, was never released.Array.joinends in"".concat(...parts), so every join leaked.Fix. MLIRGen marks the literal's final read
__spread_array_literal(SPREAD_ARRAY_LITERAL_ATTR_NAME). Under rc the pass treats it as a new array, so the call holds it and releases it afterwards, as forf(a, b). own keeps its existing handling.Paired with ASDAlexander77/TypeScriptCompilerDefaultLib#107, which fixes the
toFixed/ Date string leak. That change is library-only: it marks the sixcore.os.d.tsstring functions@owned.Measured (
-mm=rc, peak working set, 100K vs 1M iterations):"".concat(...parts)[a, b].join(",")Tests
test-rc-spread-rest-packreads the IR and checks the packed spread is retained before the call and released after it.spread-rest-packruntime tests (compile and JIT) in gc, rc, none and own.ctest -C Release -j 8: 8315/8315 pass.tests.ps1release (compile + JIT), rebuilt with this compiler and the DefaultLib branch: passes in gc, rc, none and own.Not fixed here: a temporary array literal that's only read, like
[a, b, "x"].length, still leaks under rc, with or without a spread. That's a separate, general bug.🤖 Generated with Claude Code