perf(turbopack-node): zero-copy Buffer transfer from node to rust (#91376)
Use `Bytes::from_owner(napi::Buffer)` to eliminate the `Buffer → Vec<u8>` memcpy on the JS→Rust path in the worker pool. `bytes::Bytes::from_owner` (>=1.9.0) wraps any `T: AsRef<[u8]> + Send + 'static` without copying — the data pointer comes from `T::as_ref()` and `T` is dropped when the `Bytes` is dropped. Since napi@2's `Buffer` implements `AsRef<[u8]>`, this gives true zero-copy. Also unifies the `Operation` trait to use `Bytes` for both `send` and `recv`. This also helps reduce memory consumption, without zero-copy, the memory consumption of the data returned by the loader would be doubled until GC on the JS side or dropped on the Rust side.
Showing
Please
register
or
sign in
to comment