-
Notifications
You must be signed in to change notification settings - Fork 0
perf(turbopack-node): optimize worker communication with binary transport and caching #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @xusd320, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the inter-process communication within Turbopack by transitioning from string-based message passing to a more robust and efficient binary data format. This change standardizes how task messages are serialized and deserialized across JavaScript, Rust, and WebAssembly components, laying the groundwork for improved performance and future support for non-UTF8 payloads. The core impact is a more resilient and efficient communication layer for worker operations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively refactors the task message handling to use binary data instead of strings, which is a great improvement for performance and standardization across JavaScript, Rust, and WebAssembly. The changes are consistently applied throughout the affected modules. I have one suggestion to further improve the efficiency and type safety of the WebAssembly interop code.
| let data_js = js_sys::Reflect::get(&message, &"data".into()) | ||
| .map_err(|_| JsError::new("Failed to get data"))?; | ||
|
|
||
| let data = js_sys::Uint8Array::new(&data_js).to_vec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using js_sys::Uint8Array::new(&data_js) creates a new Uint8Array and copies the data from data_js. This is less efficient than a direct cast and can lead to unexpected behavior if data_js is not an array-like object (e.g., if it's a number, it will create an empty buffer of that size).
A more direct, efficient, and type-safe approach is to cast the JsValue to js_sys::Uint8Array using dyn_into. This avoids an unnecessary copy and ensures that the incoming data is of the expected Uint8Array type.
| let data_js = js_sys::Reflect::get(&message, &"data".into()) | |
| .map_err(|_| JsError::new("Failed to get data"))?; | |
| let data = js_sys::Uint8Array::new(&data_js).to_vec(); | |
| let data = js_sys::Reflect::get(&message, &"data".into()) | |
| .map_err(|_| JsError::new("Failed to get data"))? | |
| .dyn_into::<js_sys::Uint8Array>() | |
| .map_err(|_| JsError::new("data must be a Uint8Array"))? | |
| .to_vec(); |
This pull request refactors the way task messages are handled and transmitted between worker threads and processes in the Turbopack codebase. The main improvement is transitioning from string-based message passing to using binary data (
Uint8Array/Vec<u8>/Buffer), which standardizes and streamlines serialization and deserialization across JavaScript, Rust, and WebAssembly boundaries. This change affects both the Rust backend and the JavaScript/TypeScript worker implementations.The most important changes are:
Message Data Handling and Serialization:
Stringto binary types (Uint8Array,Vec<u8>, orBuffer) throughout the Rust and JS/TS code, includingTaskMessage,Operationtrait, and worker pool interfaces. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]TextEncoder/TextDecoderin JS/TS andserde_json::to_vec/from_slicein Rust, ensuring consistent binary message encoding/decoding. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Worker and Channel API Updates:
WebAssembly and NAPI Interop:
Uint8Array/Bufferand RustVec<u8>. [1] [2] [3] [4]Cleanup and Consistency:
These changes make the worker communication more robust and efficient, and pave the way for supporting non-UTF8 or binary payloads in the future.