perf: use url to replace wasm module import#479
perf: use url to replace wasm module import#479fireairforce wants to merge 1 commit intoapt-oss:mainfrom
Conversation
|
|
💖 Thanks for opening this pull request! 💖 Please follow the contributing guidelines. And we use [semantic commit messages to streamline the release process. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
Please be patient and we will get back to you as soon as we can. |
There was a problem hiding this comment.
Pull request overview
This PR replaces the module-based WASM import with a URL-based approach to improve bundle size and build speed. Instead of importing the WASM file as a module, it now fetches the oniguruma WASM file directly from unpkg.com CDN.
- Removes the module import of
vscode-oniguruma/release/onig.wasm - Uses a direct CDN URL to fetch the WASM file at runtime
- Simplifies the URL handling logic by removing conditional checks for different path formats
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| onigurumaUrl = onigurumaPath.default; | ||
| } | ||
| const onigurumaPath = 'https://unpkg.com/[email protected]/release/onig.wasm'; | ||
| const url = new URL(onigurumaPath); |
There was a problem hiding this comment.
Creating a URL object from an absolute URL string is unnecessary overhead. The fetch() API accepts strings directly, so you can pass 'onigurumaPath' to fetch without wrapping it in a URL object first.
| if (typeof onigurumaPath !== 'string' && onigurumaPath.default) { | ||
| onigurumaUrl = onigurumaPath.default; | ||
| } | ||
| const onigurumaPath = 'https://unpkg.com/[email protected]/release/onig.wasm'; |
There was a problem hiding this comment.
Using a hardcoded external CDN URL (unpkg.com) may cause reliability issues in environments with restricted network access, offline scenarios, or if the CDN is unavailable. Consider making this URL configurable through an environment variable or configuration file, or bundling the WASM file as a fallback option.
使用
new URL('')来替代 module import 去导入 wasm 产物,这样可以避免产物的 bundle 的体积 & 构建速度。用 webpack 测试过,看上去使用上效果都是一样的。