Skip to content
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

Improve JS kit performance by precompiling the polyfill #242

Closed
Angelmmiguel opened this issue Oct 18, 2023 · 0 comments · Fixed by #257
Closed

Improve JS kit performance by precompiling the polyfill #242

Angelmmiguel opened this issue Oct 18, 2023 · 0 comments · Fixed by #257
Labels
🚀 enhancement New feature or request 🔨 sdks Issues related to language SDKs

Comments

@Angelmmiguel
Copy link
Contributor

Angelmmiguel commented Oct 18, 2023

Is your feature request related to a problem? Please describe.

Currently, we're appending the source code into the polyfill and compiling it on every request:

match identify_type(&contents) {
JSWorkerType::DefaultExport => {
let _ = context.eval_module("handler.mjs", &contents).unwrap();
let _ = context
.eval_module(
"runtime.mjs",
&format!("import {{ default as handler }} from 'handler.mjs'; addEventListener('fetch', (e) => {{ e.respondWith(handler.fetch(e.request)) }});"),
)
.unwrap();
}
_ => {
context.eval_global("handler.js", &contents).unwrap();
}
}

After adding multiple polyfills like TextEncoder and TextDecoder, the JavaScript shims library started to grow. Currently, it's about 1.1Mb (850Kb minimized). This is causing the JS requests to take ~100ms.

Describe the solution you'd like

I would like to precompile the polyfills so we eval the bytecode directly. This should improve the performance as the JS runtime doesn't need to parse and compile the polyfill over and over. To compile source code to bytecode, the Javy toolchain already provides different methods:

To store the bytecode, we can use the wizer to preinitialize and save it in a global variable.

Describe alternatives you've considered

For now, this is the only alternative I found to improve the runtime performance.

Additional context

No response

@Angelmmiguel Angelmmiguel added 🚀 enhancement New feature or request 🔨 sdks Issues related to language SDKs labels Oct 18, 2023
@Angelmmiguel Angelmmiguel added this to the 1.7.0 milestone Oct 18, 2023
@Angelmmiguel Angelmmiguel modified the milestones: v1.7.0, v1.8.0 Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request 🔨 sdks Issues related to language SDKs
Projects
None yet
1 participant