Skip to content

Commit 475b290

Browse files
committed
speed up by loading pyodide on page load
1 parent 84fe6c4 commit 475b290

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed
0 Bytes
Binary file not shown.

examples/server/webui/src/components/CanvasPyInterpreter.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useAppContext } from '../utils/app.context';
33
import { OpenInNewTab, XCloseButton } from '../utils/common';
44
import { CanvasType } from '../utils/types';
55
import { PlayIcon, StopIcon } from '@heroicons/react/24/outline';
6+
import StorageUtils from '../utils/storage';
67

78
const canInterrupt = typeof SharedArrayBuffer === 'function';
89

@@ -54,18 +55,26 @@ const interruptBuffer = canInterrupt
5455
? new Uint8Array(new SharedArrayBuffer(1))
5556
: null;
5657

58+
const startWorker = () => {
59+
if (!worker) {
60+
worker = new Worker(
61+
URL.createObjectURL(new Blob([WORKER_CODE], { type: 'text/javascript' }))
62+
);
63+
}
64+
};
65+
66+
if (StorageUtils.getConfig().pyIntepreterEnabled) {
67+
startWorker();
68+
}
69+
5770
const runCodeInWorker = (
5871
pyCode: string,
5972
callbackRunning: () => void
6073
): {
6174
donePromise: Promise<string>;
6275
interrupt: () => void;
6376
} => {
64-
if (!worker) {
65-
worker = new Worker(
66-
URL.createObjectURL(new Blob([WORKER_CODE], { type: 'text/javascript' }))
67-
);
68-
}
77+
startWorker();
6978
const id = Math.random() * 1e8;
7079
const context = {};
7180
if (interruptBuffer) {

examples/server/webui/src/components/ChatScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default function ChatScreen() {
137137
</div>
138138
</div>
139139
{canvasData && (
140-
<div className="w-full sticky top-[8em] h-[calc(100vh-9em)]">
140+
<div className="w-full sticky top-[7em] h-[calc(100vh-9em)]">
141141
<CanvasPyInterpreter />
142142
</div>
143143
)}

0 commit comments

Comments
 (0)