next.js
e8197cbf - turbo-tasks: swap TaskStorage lazy area to bitmap + packed byte tail

Commit
66 days ago
turbo-tasks: swap TaskStorage lazy area to bitmap + packed byte tail Replaces the `TinyVec<LazyField, _>` lazy area with `LazyTail`, a 16 B header (presence bitmap + len + cap + ptr) backed by a heap buffer that holds payloads packed in tag order. Per-tag layout is driven by the schema-emitted `LAZY_SIZE` / `LAZY_ALIGN` / `LAZY_PADDED_SIZE` tables and `LAZY_TAG_<NAME>` constants from the previous commit. Implementation: - `LazyTail` (new file): `present: u32, len: u16, cap: u16, ptr: NonNull<u8>` with `find::<T>`, `find_mut::<T>`, `install::<T>`, `take::<T>`, `replace::<T>` primitives. All unsafe; callers pass the schema's tag for the matching payload type. Geometric grow policy (64 → power of two, capped at u16::MAX). - Macro-emitted accessors (`<name>`, `<name>_mut`, `get_<name>`, `set_<name>`, `take_<name>`, `get_<name>_mut`) now call directly into `LazyTail`'s typed primitives via the per-variant `LAZY_TAG_*` constant. The previous inline `match LazyField::V(v) => ...` patterns are gone. - `encode_*` / `decode_*` keep their on-disk format (per-category 1-based tag + payload + sentinel) but route decoded payloads to the global `LAZY_TAG_<NAME>` for tail installation, so the bitmap position is correct. - `clone_snapshot` and `restore_*_from` use `LazyTail::install` / `std::mem::take(&mut source.<field>)` so the `Drop` impl below doesn't block partial moves. - `TaskStorage` now has a hand-written `Drop` that walks `present`, invokes the macro-emitted `lazy_drop_dispatch(tag, ptr)` per payload, then lets `LazyTail`'s field-level Drop free the buffer. - Padded sizes round up to `LAZY_MAX_ALIGN` so every payload lands at an offset valid for its own alignment regardless of variant order — a smaller-aligned variant followed by a stricter-aligned one would otherwise misalign reads. `LazyField` is still around (encode/decode arms use it as a stable on- disk tag mapping) and `test_schema_size` still asserts `size_of::<TaskStorage>() == 128`. The `TinyVec<LazyField, _>` field is gone. All 50 backend tests pass; whole workspace builds.
Author
Committer
Parents
Loading