Skip to content

refactor(utoo-wasm): replace sabcom with rust sync fs apis - #2460

Merged
xusd320 merged 2 commits into
nextfrom
fix/wasm-fs-sync-polyfill
Dec 26, 2025
Merged

refactor(utoo-wasm): replace sabcom with rust sync fs apis#2460
xusd320 merged 2 commits into
nextfrom
fix/wasm-fs-sync-polyfill

Conversation

@xusd320

@xusd320 xusd320 commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

This pull request introduces several significant changes focused on improving the file system operations in the WASM and web worker environment. The main updates include adding synchronous file system APIs to the WASM layer, updating memory configuration for WASM, and cleaning up unused shared array buffer (SAB) communication code in the web worker loader and polyfills.

WASM file system enhancements:

  • Added a suite of synchronous file system methods to the Project class in crates/utoo-wasm/src/project.rs, including readSync, readDirSync, writeSync, createDirSync, createDirAllSync, copyFileSync, removeFileSync, removeDirSync, and metadataSync. These methods use a oneshot channel to bridge async Rust code into synchronous JS calls, enabling blocking file system operations from JavaScript.
  • Updated the async read method of Project to return a js_sys::Uint8Array instead of a Vec<u8>, improving compatibility with JavaScript consumers.
  • Added the oneshot crate as a dependency to support the new synchronous APIs.

WASM build configuration:

  • Adjusted the WASM memory initialization in .cargo/config.toml by explicitly setting --initial-memory=67108864 (64MB) and reordering --max-memory to ensure proper memory configuration for the WASM runtime.

Web worker and polyfill cleanup:

  • Removed the now-unused sabcom.ts shared array buffer communication code, indicating a shift away from SAB-based sync file system emulation in the web worker environment.
  • Cleaned up references to SAB communication and related logic in loaderWorkerPool.ts and fsPolyfill.ts, simplifying worker setup and file system polyfills. [1] [2] [3] [4] [5]

CommonJS loader improvements:

  • Simplified and improved error handling in the CJS loader by throwing an error when a dependency cannot be found, rather than returning an empty object.
  • Changed module resolution logic to use path.join instead of path.resolve for relative paths, ensuring correct path joining semantics.
  • Removed unused statSync and existsSync cache logic from the CJS loader, further cleaning up the codebase.

These changes collectively modernize and streamline the WASM file system interface, improve memory handling, and remove legacy SAB-based code from the web worker environment.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 file system operations within the WASM and web worker environment by replacing the Shared Array Buffer (SAB) based synchronization mechanism with native Rust synchronous file system APIs. The core change involves introducing a new set of synchronous file system methods to the WASM Project class, which are then utilized by the JavaScript-side polyfills. This modernization effort also includes optimizing WASM memory configuration and streamlining the CommonJS loader by improving error handling and removing obsolete SAB-related code, leading to a cleaner and potentially more performant codebase.

Highlights

  • WASM File System Enhancements: A comprehensive suite of synchronous file system methods (readSync, writeSync, createDirSync, etc.) has been added to the Project class in crates/utoo-wasm/src/project.rs. These methods leverage a oneshot channel to bridge asynchronous Rust code into synchronous JavaScript calls, enabling blocking file system operations from JavaScript.
  • SAB Communication Removal: The legacy Shared Array Buffer (SAB) communication code, previously used for synchronous file system emulation, has been entirely removed from packages/utoo-web/src/utils/sabcom.ts and its references cleaned up in loaderWorkerPool.ts and fsPolyfill.ts. This signifies a shift to the new Rust-based synchronous APIs.
  • WASM Memory Configuration Update: The WASM build configuration in .cargo/config.toml has been adjusted to explicitly set --initial-memory=67108864 (64MB) and reorder the --max-memory argument, ensuring proper memory allocation for the WASM runtime.
  • CommonJS Loader Improvements: The CommonJS loader in packages/utoo-web/src/webpackLoaders/cjs.ts now throws an error when a dependency cannot be found, improving error handling. It also uses path.join for relative path resolution and removes unused statSync and existsSync cache logic.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 is a great refactoring that replaces the sabcom implementation with new synchronous Rust APIs for file system operations, which simplifies the codebase significantly. I've found a critical bug in the rmSync polyfill and a high-severity functional regression in statSync where timestamps are no longer correctly reported. I've also included a medium-severity suggestion to reduce code duplication in the new Rust sync functions.

Comment thread packages/utoo-web/src/webpackLoaders/polyfills/fsPolyfill.ts
Comment thread packages/utoo-web/src/webpackLoaders/polyfills/fsPolyfill.ts
Comment thread crates/utoo-wasm/src/project.rs

@fireairforce fireairforce left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥没有依赖变更 lock 文件变了

@xusd320
xusd320 force-pushed the fix/wasm-fs-sync-polyfill branch from a9f27de to 6cb69b1 Compare December 26, 2025 10:24
fireairforce
fireairforce previously approved these changes Dec 26, 2025
@xusd320
xusd320 force-pushed the fix/wasm-fs-sync-polyfill branch from 8553771 to 811eee2 Compare December 26, 2025 10:33
@xusd320

xusd320 commented Dec 26, 2025

Copy link
Copy Markdown
Contributor Author

为啥没有依赖变更 lock 文件变了

跨分支保存了。reset 掉了

@xusd320
xusd320 merged commit 8c020ae into next Dec 26, 2025
21 checks passed
@xusd320
xusd320 deleted the fix/wasm-fs-sync-polyfill branch December 26, 2025 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants