Skip to content

migrate turbo-tasks to scattered collect#94503

Open
lukesandberg wants to merge 4 commits into
06-05-migrate_rcstr_to_use_scattered_collectfrom
06-05-migrate_turbo-tasks_to_scattered_collect
Open

migrate turbo-tasks to scattered collect#94503
lukesandberg wants to merge 4 commits into
06-05-migrate_rcstr_to_use_scattered_collectfrom
06-05-migrate_turbo-tasks_to_scattered_collect

Conversation

@lukesandberg
Copy link
Copy Markdown
Contributor

@lukesandberg lukesandberg commented Jun 6, 2026

What

This uses scatter_collect from @mmastrac to register all values, traits and value impls of traits. now all data can be consistently accessed when constructing the VALUEs registry, eliminating a number of racy access opportunities.

Why

Scatter collect uses link sections to gather registries at link time, this resolve some inherent brittleness in constructor functions since the relative execution order is not guaranteed and it is also to even detect execution that is too early.

We have a single report that appears to be due to this

web:dev: thread 'tokio-rt-worker' (41574444) panicked at turbopack/crates/turbo-tasks/src/macro_helpers.rs:274:13:
web:dev: no trait impl registered for value type turbopack_core::module_graph::ModuleGraphImportTracer
web:dev: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Which implies a race condition somewhere in our value registration. Unfortunately initialization logic is brittle since it relies on

  • an inventory of all value types
  • an inventory of all trait types
  • a set of ctor functions to register trait implementations (basically value, trait pairs)

All of these need to be initialized before the VALUES registry is accessed, but the above panic implies that the ctor function for ModuleGraphImportTracer to register its implementation of ImportTracer hasn't occurred yet.

By moving to link time registration we completely eliminate all startup races since the linker does all the 'gathering'

Copy link
Copy Markdown
Contributor Author

lukesandberg commented Jun 6, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

Stats cancelled

Commit: 5d27669
View workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

Failing test suites

Commit: 5d27669 | About building and testing Next.js

pnpm test test/unit/image-optimizer/lru-disk-eviction.test.ts (job)

  • LRU disk eviction > should evict old entries when new entries are set (DD)
Expand output

● LRU disk eviction › should evict old entries when new entries are set

expect(received).toEqual(expected) // deep equality

- Expected  - 0
+ Received  + 1

  Array [
+   "new-a",
    "new-b",
    "new-c",
  ]

  118 |     await setTimeout(100)
  119 |     const contents = await promises.readdir(cacheDir)
> 120 |     expect(contents).toEqual(['new-b', 'new-c'])
      |                      ^
  121 |   })
  122 |
  123 |   it('should promote entries on get() to prevent eviction', async () => {

  at Object.toEqual (unit/image-optimizer/lru-disk-eviction.test.ts:120:22)

@lukesandberg lukesandberg force-pushed the 06-05-migrate_turbo-tasks_to_scattered_collect branch 2 times, most recently from ee21662 to ea3f40c Compare June 6, 2026 22:57
@lukesandberg lukesandberg force-pushed the 06-05-migrate_turbo-tasks_to_scattered_collect branch from ea3f40c to c9c8d46 Compare June 6, 2026 23:03
Comment thread turbopack/crates/turbo-tasks-macros/src/value_impl_macro.rs Outdated
@lukesandberg lukesandberg marked this pull request as ready for review June 7, 2026 06:10
@lukesandberg lukesandberg requested review from a team and bgw June 7, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant