-
Notifications
You must be signed in to change notification settings - Fork 83
Replace Facade Proxy with handwritten proxy. #285
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
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.
Summary of Changes
Hello @rhashimoto, 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 focuses on a significant refactoring within the FacadeVFS to enhance performance. By replacing the existing JavaScript Proxy-based wrappers for WebAssembly memory access with custom-built proxy classes, I've aimed to reduce runtime overhead and provide more efficient handling of memory buffers, especially in scenarios where WebAssembly memory is frequently resized.
Highlights
- Performance Optimization: I've replaced the use of built-in JavaScript
Proxyobjects within theFacadeVFSimplementation with custom, handwritten classes (Uint8ArrayProxyandDataViewProxy). This change aims to reduce the performance overhead associated withProxyobjects, particularly noticeable in VFS implementations that primarily operate in memory, such asMemoryVFSandMemoryAsyncVFS. - Custom Buffer Handling for WebAssembly Memory: New
Uint8ArrayProxyandDataViewProxyclasses have been introduced. These classes mimic the behavior and methods of their nativeUint8ArrayandDataViewcounterparts, respectively. Crucially, they include logic to automatically reacquire the underlying WebAssembly memory buffer when it is resized or detached, ensuring continued valid access to memory regions. - Refactored Memory Access Methods: The internal
#makeTypedDataViewand#makeDataArraymethods inFacadeVFShave been updated. Instead of returningProxywrappers around nativeDataVieworUint8Arrayobjects, they now instantiate and return instances of the newly createdDataViewProxyandUint8ArrayProxyclasses.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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
-
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. ↩
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 introduces handwritten proxy classes (Uint8ArrayProxy and DataViewProxy) to replace the standard JavaScript Proxy mechanism for accessing WebAssembly memory in FacadeVFS.js to enhance performance. The new proxies correctly handle WebAssembly memory resizes. The review focuses on ensuring type clarity in JSDoc and addressing // @ts-ignore comments.
|
|
||
| // Copy data. | ||
| new Uint8Array(file.data, iOffset, pData.byteLength).set(pData); | ||
| new Uint8Array(file.data, iOffset, pData.byteLength).set(pData.subarray()); |
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.
| // @ts-ignore | ||
| return new DataViewProxy(this._module, byteOffset, type); |
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.
| * is resized. | ||
| * @param {number} byteOffset | ||
| * @param {number} byteLength | ||
| * @returns {Uint8Array} |
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.
| } | ||
|
|
||
| /** | ||
| * @param {*} module |
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.
| return this.#array.subarray(begin, end); | ||
| } | ||
| toLocaleString(locales, options) { | ||
| // @ts-ignore |
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.
| } | ||
|
|
||
| /** | ||
| * @param {*} module |
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.
* Replace Proxy with handwritten proxy for jRead/jWrite buffers. * Replace Proxy with handwritten proxy for VFS return data. --------- Co-authored-by: Roy Hashimoto <[email protected]>
* Update issue templates * Replace Facade Proxy with handwritten proxy. (rhashimoto#285) * Replace Proxy with handwritten proxy for jRead/jWrite buffers. * Replace Proxy with handwritten proxy for VFS return data. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Use non-CAPTCHA SQLite download URL. (rhashimoto#289) * Use non-CAPTCHA SQLite download URL. * Use consistent Makefile variable bracing. --------- Co-authored-by: Roy Hashimoto <[email protected]> * update build * added changeset --------- Co-authored-by: Roy Hashimoto <[email protected]> Co-authored-by: Roy Hashimoto <[email protected]>
* Fix resetting isHandleRequested * Bump package version. * Fix hello demo import paths. * Permit JS booleans to be bound to queries, as integer 0/1 values (rhashimoto#272) * Permit boolean values to be bound to statements, as 0/1 * Add test for boolean binding * Using a single TextEncoder for all string conversions * Export HEAP* module members for recent EMSDK changes. * Bump tar-fs from 3.0.8 to 3.0.9 Bumps [tar-fs](https://github.com/mafintosh/tar-fs) from 3.0.8 to 3.0.9. - [Commits](mafintosh/tar-fs@v3.0.8...v3.0.9) --- updated-dependencies: - dependency-name: tar-fs dependency-version: 3.0.9 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Update SQLite to 3.50.1. * Bump package version. * Update issue templates * Replace Facade Proxy with handwritten proxy. (rhashimoto#285) * Replace Proxy with handwritten proxy for jRead/jWrite buffers. * Replace Proxy with handwritten proxy for VFS return data. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Use non-CAPTCHA SQLite download URL. (rhashimoto#289) * Use non-CAPTCHA SQLite download URL. * Use consistent Makefile variable bracing. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Fix WebLocksMixin state initialization. (rhashimoto#293) * Fix WebLocksMixin state initialization. * Don't fetch state in WebLocksMixin file control unnecessarily. * Minor fixes. --------- Co-authored-by: Roy Hashimoto <[email protected]> * Bump package version. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Simon Binder <[email protected]> Co-authored-by: Roy Hashimoto <[email protected]> Co-authored-by: Grant Cox <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
See #273
Using Proxy in the Facade implementation is convenient but has a performance cost. It is most noticeable with MemoryVFS and MemoryAsyncVFS; less so with VFS classes where persistent storage API calls (e.g. to OPFS and IndexedDB) become the bottleneck.
This PR replaces the use of Proxy in Facade with handwritten classes that have the same methods as
Uint8ArrayandDataViewfor a small performance optimization.