Skip to content

Commit c17942f

Browse files
authored
Unroll recursion in RuleCondition::matches This trades allocations due to Box::pin calls during recursion for an explicit stack and a tiny interpreter loop. (#79310)
### What? Replace recursion with an explicit stack to reduce allocations. Also, add tests! This trims peak heap in a build of `vercel-site` by 100-300m, see https://vercel.slack.com/archives/C06PPGZ0FD3/p1747438469043789?thread_ts=1746823119.596949&cid=C06PPGZ0FD3 ### Why? This replaces a lot of `Box::pin` calls during evaluation, instead we can amortize the heap allocation cost by pushing items onto explicit stack. This is managed as a SmallVec so in many cases we should be able to avoid allocations. ### How? Tediously introduce a small bytecode machine... sigh. The main alternatives considered were: * pulling all `awaits` up to the top level and using a normal recursive function. This works, but would be limiting when we inevitably add another async dependency on the `Source::content` * eliminating asynchrony from `Source::ident`. This turned out to be controversial (see discussion in linear) and incredibly complex to implement so it is deferred. Closes PACK-4560
1 parent 243d225 commit c17942f

File tree

3 files changed

+447
-54
lines changed

3 files changed

+447
-54
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

turbopack/crates/turbopack/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ rstest_reuse = "0.5.0"
5454
tokio = { workspace = true }
5555
turbo-tasks-malloc = { workspace = true, default-features = false }
5656
turbo-tasks-memory = { workspace = true }
57+
turbo-tasks-backend = { workspace = true }
5758

5859
[build-dependencies]
5960
turbo-tasks-build = { workspace = true }

0 commit comments

Comments
 (0)