Commit 3d3405a
authored
[turbopack] use zero copy qfilter deserialization (#90574)
## What
Switch turbo-persistence AMQF filters from owned `qfilter::Filter` (heap-allocated) to zero-copy `qfilter::FilterRef` that borrows directly from the memory-mapped meta file.
## Why
- **Lower memory usage** — no heap copy of filter data; `FilterRef` is just a pointer into the mmap
- **Faster open time** — no deserialization/allocation, just pointer math over the mmap
- **OS-managed memory** — mmap pages can be cheaply evicted under pressure (free LRU behavior), unlike heap-allocated `Filter` data which needs to be swapped
## How
- Update `qfilter` dependency to the latest alpha release with `FilterRef` support
- Switch per-entry AMQF serialization from `turbo_bincode` to `pot` format, which supports zero-copy deserialization
- Store `qfilter::FilterRef<'static>` directly in `MetaEntry` (lifetime transmuted from the mmap borrow)
- Rely on Rust's struct field drop order guarantee: `MetaFile::entries` is declared before `MetaFile::mmap`, so all `FilterRef`s are dropped before the mmap is unmapped
- Update compaction code to work with `FilterRef` avoiding many allocations when merging
### Safety invariants
The `FilterRef<'static>` lifetime is transmuted 🙀 — the actual borrow is from `MetaFile::mmap`. This is safe because:
1. `MetaEntry` is never moved out of `MetaFile` (only accessed by `&` reference via `entries()` / `entry()`)
2. Rust drops struct fields in declaration order, and `entries` is declared before `mmap`
3. This is the same pattern used by `ArcBytes`/`RcBytes` in this crate (raw pointer into backing storage)
## Benchmark Results
I ran a number of the Read benchmarks and compaction benchmarks and it is all in the noise, which makes sense. We might get a slight benefit from avoiding the `OnceLock` and lazy initialization, we should also have slightly lower maxrss and offer the OS more flexibility during memory pressure
From measuring vercel-site, a warm build saves ~40m of MaxRSS1 parent 3c301ac commit 3d3405a
7 files changed
Lines changed: 188 additions & 141 deletions
File tree
- turbopack/crates/turbo-persistence
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | 27 | | |
30 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
531 | 536 | | |
532 | 537 | | |
533 | 538 | | |
| |||
987 | 992 | | |
988 | 993 | | |
989 | 994 | | |
990 | | - | |
| 995 | + | |
991 | 996 | | |
992 | 997 | | |
993 | 998 | | |
| |||
1001 | 1006 | | |
1002 | 1007 | | |
1003 | 1008 | | |
1004 | | - | |
| 1009 | + | |
1005 | 1010 | | |
1006 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
1007 | 1014 | | |
1008 | 1015 | | |
1009 | 1016 | | |
| |||
0 commit comments