next.js
678a4aa9 - [turbopack] optimize RcStr parsing (#91773)

Commit
2 days ago
[turbopack] optimize RcStr parsing (#91773) `RcStr` has 3 internal forms * `INLINE` meaning it is small enough that the bytes are stored inline (7 bytes) * `STATIC` meaning it was allocated by `rcstr!` and is stored in a `static` item somewhere * `DYNAMIC` meaning it is stored in an `Arc` The nice thing is that `INLINE` and `STATIC` are not ref-counted which optimizes clones. The unfortunate thing is that serialization round trips partially defeat these optimizations. To fix that we do two things 1. decode to a `&str` instead of a `String` so we can defer the allocation to if/when we select the `DYNAMIC` format 2. store all static strings in an inventory managed hashtable (lazily constructed) so we can match against them when deserializing them This allows us to avoid temporary allocations during decoding for the `inline` case and completely eliminate them for the static case. The dynamic case simply pays the cost of probing the static hash table and defers the allocation to slightly later. The hash probe is not free but the table is small ~1500 entries, so this overhead should be negligible Also i needed to update our `wasm-bindgen` versions to workaround https://github.com/wasm-bindgen/wasm-bindgen/issues/4446
Author
Parents
Loading