next.js
7ec95283 - Turbopack: add support for selective reads of keyed cell values (#88303)

Commit
7 days ago
Turbopack: add support for selective reads of keyed cell values (#88303) ### What? Previously cells could either be unchanged or changed. This falls short when updating Maps or Sets. We can't have a dependency on a single key of a map or set. The workaround for this was to create an "selector" turbo-tasks which picks the value and copies it into a new cell. This allows more granular invalidation. But it also creates a lot of extra tasks. And changing the map/set does invalidate all these selector tasks, which causes a lot of invalidation work. This change adds support for dependencies on certain keys of cells. On write side a turbo-tasks value need to opt-in into that behavior via `cell = "keyed"`. This changes the `cell` method to compare the new value key-by-key and report the changed keys to the backend. On read side the Vc need to be read via `.get(key).await?` or `.contains_key(key).await?`, which returns only the value resp. existance of the key and adds a dependency only to that key. With this approach the "selector" tasks can be avoided, while maintaining the same level of invalidation. ### How? On implementation side we only track the hash of the key for size reasons. A dependency has an additional field `key: Option<u64>` which represents the key depending on. When updating a cell we have a new optional argument `updated_key_hashes: Option<SmallVec<[u64; 2]>>` where the updates keys can be provided. The new `CellMode` (cell = "keyed") fills that.
Author
Parents
Loading