Cache the scripts on disk, in attempt to increase perfrmance, may need to revisit this

This commit is contained in:
Peter Stockings
2025-07-26 21:50:45 +10:00
parent 748771dc33
commit 4a335dc936
5 changed files with 95 additions and 77 deletions

View File

@@ -8,7 +8,7 @@ const States = Object.freeze({
});
self.onmessage = async (e) => {
const { code, request, environment, name } = e.data;
const { filePath, request, environment, name } = e.data;
const logs: any[] = [];
const startTime = performance.now();
@@ -52,15 +52,7 @@ self.onmessage = async (e) => {
status
);
let userModule = moduleCache.get(code);
if (!userModule) {
// Use a data URL to import the user's code as an ES module.
const dataUrl = `data:text/javascript;base64,${btoa(
unescape(encodeURIComponent(code))
)}`;
userModule = await import(dataUrl);
moduleCache.set(code, userModule);
}
const userModule = await import(filePath);
if (typeof userModule.default !== "function") {
throw new Error(