Unverified Commit c17942f9 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Unroll recursion in `RuleCondition::matches` This trades allocations due to…

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
parent 243d225a
...@@ -9896,6 +9896,7 @@ dependencies = [ ...@@ -9896,6 +9896,7 @@ dependencies = [
"turbo-esregex", "turbo-esregex",
"turbo-rcstr", "turbo-rcstr",
"turbo-tasks", "turbo-tasks",
"turbo-tasks-backend",
"turbo-tasks-build", "turbo-tasks-build",
"turbo-tasks-env", "turbo-tasks-env",
"turbo-tasks-fs", "turbo-tasks-fs",
......
...@@ -54,6 +54,7 @@ rstest_reuse = "0.5.0" ...@@ -54,6 +54,7 @@ rstest_reuse = "0.5.0"
tokio = { workspace = true } tokio = { workspace = true }
turbo-tasks-malloc = { workspace = true, default-features = false } turbo-tasks-malloc = { workspace = true, default-features = false }
turbo-tasks-memory = { workspace = true } turbo-tasks-memory = { workspace = true }
turbo-tasks-backend = { workspace = true }
[build-dependencies] [build-dependencies]
turbo-tasks-build = { workspace = true } turbo-tasks-build = { workspace = true }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment