Skip to content

Commit 0164b59

Browse files
Use postMessage instead of a comlink produced MessageChannel (#148)
* Update comlink to 4.4.2 - increases performance * Use postMessage instead of a comlink produced MessageChannel * Deduplicate packages * Rename jMsg to _kernelMessage for comlink * Fix lock file
1 parent fb9c10d commit 0164b59

File tree

4 files changed

+31
-131
lines changed

4 files changed

+31
-131
lines changed

packages/pyodide-kernel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@jupyterlite/contents": "^0.4.5",
5959
"@jupyterlite/kernel": "^0.4.5",
6060
"coincident": "^1.2.3",
61-
"comlink": "^4.4.1"
61+
"comlink": "^4.4.2"
6262
},
6363
"devDependencies": {
6464
"@babel/core": "^7.22.17",

packages/pyodide-kernel/src/comlink.worker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class PyodideDriveFS extends DriveFS {
2929
}
3030

3131
export class PyodideComlinkKernel extends PyodideRemoteKernel {
32+
constructor() {
33+
super();
34+
this._sendWorkerMessage = (msg: any) => {
35+
// use postMessage, but in a format, that comlink would not process.
36+
postMessage({ _kernelMessage: msg });
37+
};
38+
}
39+
3240
/**
3341
* Setup custom Emscripten FileSystem
3442
*/

packages/pyodide-kernel/src/kernel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import coincident from 'coincident';
22

3-
import { Remote, proxy, wrap } from 'comlink';
3+
import { Remote, wrap } from 'comlink';
44

55
import { PromiseDelegate } from '@lumino/coreutils';
66

@@ -86,7 +86,13 @@ export class PyodideKernel extends BaseKernel implements IKernel {
8686
};
8787
} else {
8888
remote = wrap(this._worker) as IPyodideWorkerKernel;
89-
remote.registerCallback(proxy(this._processWorkerMessage.bind(this)));
89+
// we use the normal postMessage mechanism
90+
this._worker.addEventListener('message', (ev) => {
91+
if (typeof ev?.data?._kernelMessage !== 'undefined') {
92+
// only process non comlink messages
93+
this._processWorkerMessage(ev.data._kernelMessage);
94+
}
95+
});
9096
}
9197
const remoteOptions = this.initRemoteOptions(options);
9298
remote.initialize(remoteOptions).then(this._ready.resolve.bind(this._ready));

yarn.lock

Lines changed: 14 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,21 +2482,7 @@ __metadata:
24822482
languageName: node
24832483
linkType: hard
24842484

2485-
"@jupyterlab/coreutils@npm:^6.1.1, @jupyterlab/coreutils@npm:^6.2.5":
2486-
version: 6.3.0
2487-
resolution: "@jupyterlab/coreutils@npm:6.3.0"
2488-
dependencies:
2489-
"@lumino/coreutils": ^2.2.0
2490-
"@lumino/disposable": ^2.1.3
2491-
"@lumino/signaling": ^2.1.3
2492-
minimist: ~1.2.0
2493-
path-browserify: ^1.0.0
2494-
url-parse: ~1.5.4
2495-
checksum: 9e235685a1a5839a26a4fe44547be6bd1f0788809bd423c6d0d1a2ee09e24885246f5f7085d48db47245f52d138a7352f796c10813efebd70e38e6af11186122
2496-
languageName: node
2497-
linkType: hard
2498-
2499-
"@jupyterlab/coreutils@npm:~6.2.5":
2485+
"@jupyterlab/coreutils@npm:^6.1.1, @jupyterlab/coreutils@npm:^6.2.5, @jupyterlab/coreutils@npm:~6.2.5":
25002486
version: 6.2.5
25012487
resolution: "@jupyterlab/coreutils@npm:6.2.5"
25022488
dependencies:
@@ -2629,16 +2615,7 @@ __metadata:
26292615
languageName: node
26302616
linkType: hard
26312617

2632-
"@jupyterlab/nbformat@npm:^3.0.0 || ^4.0.0-alpha.21 || ^4.0.0, @jupyterlab/nbformat@npm:^4.1.1, @jupyterlab/nbformat@npm:^4.2.5, @jupyterlab/nbformat@npm:^4.3.0":
2633-
version: 4.3.0
2634-
resolution: "@jupyterlab/nbformat@npm:4.3.0"
2635-
dependencies:
2636-
"@lumino/coreutils": ^2.2.0
2637-
checksum: 52e23a2568bf01741196321a5960c13b86ab55318a2e3a3ebde71fc1b89347279acd342a4cddf6ab8b47a4cc3cdd8fe03f206f68115a9d6ac433b0b0582c13ed
2638-
languageName: node
2639-
linkType: hard
2640-
2641-
"@jupyterlab/nbformat@npm:^4.2.6":
2618+
"@jupyterlab/nbformat@npm:^3.0.0 || ^4.0.0-alpha.21 || ^4.0.0, @jupyterlab/nbformat@npm:^4.1.1, @jupyterlab/nbformat@npm:^4.2.5, @jupyterlab/nbformat@npm:^4.2.6":
26422619
version: 4.3.2
26432620
resolution: "@jupyterlab/nbformat@npm:4.3.2"
26442621
dependencies:
@@ -2777,26 +2754,7 @@ __metadata:
27772754
languageName: node
27782755
linkType: hard
27792756

2780-
"@jupyterlab/settingregistry@npm:^4.1.1, @jupyterlab/settingregistry@npm:^4.2.5":
2781-
version: 4.3.0
2782-
resolution: "@jupyterlab/settingregistry@npm:4.3.0"
2783-
dependencies:
2784-
"@jupyterlab/nbformat": ^4.3.0
2785-
"@jupyterlab/statedb": ^4.3.0
2786-
"@lumino/commands": ^2.3.1
2787-
"@lumino/coreutils": ^2.2.0
2788-
"@lumino/disposable": ^2.1.3
2789-
"@lumino/signaling": ^2.1.3
2790-
"@rjsf/utils": ^5.13.4
2791-
ajv: ^8.12.0
2792-
json5: ^2.2.3
2793-
peerDependencies:
2794-
react: ">=16"
2795-
checksum: 6a0c47b3be2188e487ec74c3ccd9e199c99a72533367b727a913d45d7096dbbb2757a63e55e5d4a9be51fbd274fe6f5f42ee1a6f021fd6a782885d6d58a3f957
2796-
languageName: node
2797-
linkType: hard
2798-
2799-
"@jupyterlab/settingregistry@npm:~4.2.5":
2757+
"@jupyterlab/settingregistry@npm:^4.1.1, @jupyterlab/settingregistry@npm:^4.2.5, @jupyterlab/settingregistry@npm:~4.2.5":
28002758
version: 4.2.6
28012759
resolution: "@jupyterlab/settingregistry@npm:4.2.6"
28022760
dependencies:
@@ -2815,20 +2773,7 @@ __metadata:
28152773
languageName: node
28162774
linkType: hard
28172775

2818-
"@jupyterlab/statedb@npm:^4.1.1, @jupyterlab/statedb@npm:^4.2.5, @jupyterlab/statedb@npm:^4.3.0":
2819-
version: 4.3.0
2820-
resolution: "@jupyterlab/statedb@npm:4.3.0"
2821-
dependencies:
2822-
"@lumino/commands": ^2.3.1
2823-
"@lumino/coreutils": ^2.2.0
2824-
"@lumino/disposable": ^2.1.3
2825-
"@lumino/properties": ^2.0.2
2826-
"@lumino/signaling": ^2.1.3
2827-
checksum: 68e1a8bffe41a236d34cb8135e0ebf906e1d087ff71d2f1e135c7cd369c7b5e2e675765d5a0627a2487a831141cb06a9ce880609ec9988b0f7e5a0156f4212f3
2828-
languageName: node
2829-
linkType: hard
2830-
2831-
"@jupyterlab/statedb@npm:^4.2.6":
2776+
"@jupyterlab/statedb@npm:^4.1.1, @jupyterlab/statedb@npm:^4.2.5, @jupyterlab/statedb@npm:^4.2.6":
28322777
version: 4.3.2
28332778
resolution: "@jupyterlab/statedb@npm:4.3.2"
28342779
dependencies:
@@ -3061,7 +3006,7 @@ __metadata:
30613006
"@jupyterlite/kernel": ^0.4.5
30623007
"@types/jest": ^29.5.4
30633008
coincident: ^1.2.3
3064-
comlink: ^4.4.1
3009+
comlink: ^4.4.2
30653010
esbuild: ^0.19.2
30663011
jest: ^29.7.0
30673012
pyodide: 0.26.4
@@ -3379,18 +3324,7 @@ __metadata:
33793324
languageName: node
33803325
linkType: hard
33813326

3382-
"@lumino/application@npm:^2.3.0, @lumino/application@npm:^2.3.1":
3383-
version: 2.3.1
3384-
resolution: "@lumino/application@npm:2.3.1"
3385-
dependencies:
3386-
"@lumino/commands": ^2.3.0
3387-
"@lumino/coreutils": ^2.1.2
3388-
"@lumino/widgets": ^2.3.2
3389-
checksum: c112789d99baf62e5c2cee98834bc3efb5027bbca1aac81f10ea8855c0cd2538ec0a7c56c3f5dd42dce244e6892ef5bf8ef356f97e1cd4c161b99eb2068c195c
3390-
languageName: node
3391-
linkType: hard
3392-
3393-
"@lumino/application@npm:^2.4.1":
3327+
"@lumino/application@npm:^2.3.0, @lumino/application@npm:^2.3.1, @lumino/application@npm:^2.4.1":
33943328
version: 2.4.1
33953329
resolution: "@lumino/application@npm:2.4.1"
33963330
dependencies:
@@ -3401,15 +3335,6 @@ __metadata:
34013335
languageName: node
34023336
linkType: hard
34033337

3404-
"@lumino/collections@npm:^2.0.1":
3405-
version: 2.0.1
3406-
resolution: "@lumino/collections@npm:2.0.1"
3407-
dependencies:
3408-
"@lumino/algorithm": ^2.0.1
3409-
checksum: 8a29b7973a388a33c5beda0819dcd2dc2aad51a8406dcfd4581b055a9f77a39dc5800f7a8b4ae3c0bb97ae7b56a7a869e2560ffb7a920a28e93b477ba05907d6
3410-
languageName: node
3411-
linkType: hard
3412-
34133338
"@lumino/collections@npm:^2.0.2":
34143339
version: 2.0.2
34153340
resolution: "@lumino/collections@npm:2.0.2"
@@ -3459,17 +3384,7 @@ __metadata:
34593384
languageName: node
34603385
linkType: hard
34613386

3462-
"@lumino/dragdrop@npm:^2.1.4":
3463-
version: 2.1.4
3464-
resolution: "@lumino/dragdrop@npm:2.1.4"
3465-
dependencies:
3466-
"@lumino/coreutils": ^2.1.2
3467-
"@lumino/disposable": ^2.1.2
3468-
checksum: 43d82484b13b38b612e7dfb424a840ed6a38d0db778af10655c4ba235c67b5b12db1683929b35a36ab2845f77466066dfd1ee25c1c273e8e175677eba9dc560d
3469-
languageName: node
3470-
linkType: hard
3471-
3472-
"@lumino/dragdrop@npm:^2.1.5":
3387+
"@lumino/dragdrop@npm:^2.1.4, @lumino/dragdrop@npm:^2.1.5":
34733388
version: 2.1.5
34743389
resolution: "@lumino/dragdrop@npm:2.1.5"
34753390
dependencies:
@@ -3479,24 +3394,14 @@ __metadata:
34793394
languageName: node
34803395
linkType: hard
34813396

3482-
"@lumino/keyboard@npm:^2.0.1, @lumino/keyboard@npm:^2.0.2":
3397+
"@lumino/keyboard@npm:^2.0.2":
34833398
version: 2.0.2
34843399
resolution: "@lumino/keyboard@npm:2.0.2"
34853400
checksum: 198e8c17825c9a831fa0770f58a71574b936acb0f0bbbe7f8feb73d89686dda7ff41fcb02d12b401f5d462b45fe0bba24f7f38befb7cefe0826576559f0bee6d
34863401
languageName: node
34873402
linkType: hard
34883403

3489-
"@lumino/messaging@npm:^2.0.1":
3490-
version: 2.0.1
3491-
resolution: "@lumino/messaging@npm:2.0.1"
3492-
dependencies:
3493-
"@lumino/algorithm": ^2.0.1
3494-
"@lumino/collections": ^2.0.1
3495-
checksum: 964c4651c374b17452b4252b7d71500b32d2ecd87c192fc5bcf5d3bd1070661d78d07edcac8eca7d1d6fd50aa25992505485e1296d6dd995691b8e349b652045
3496-
languageName: node
3497-
linkType: hard
3498-
3499-
"@lumino/messaging@npm:^2.0.2":
3404+
"@lumino/messaging@npm:^2.0.1, @lumino/messaging@npm:^2.0.2":
35003405
version: 2.0.2
35013406
resolution: "@lumino/messaging@npm:2.0.2"
35023407
dependencies:
@@ -3543,26 +3448,7 @@ __metadata:
35433448
languageName: node
35443449
linkType: hard
35453450

3546-
"@lumino/widgets@npm:^1.37.2 || ^2.3.1, @lumino/widgets@npm:^2.3.1, @lumino/widgets@npm:^2.3.2":
3547-
version: 2.3.2
3548-
resolution: "@lumino/widgets@npm:2.3.2"
3549-
dependencies:
3550-
"@lumino/algorithm": ^2.0.1
3551-
"@lumino/commands": ^2.3.0
3552-
"@lumino/coreutils": ^2.1.2
3553-
"@lumino/disposable": ^2.1.2
3554-
"@lumino/domutils": ^2.0.1
3555-
"@lumino/dragdrop": ^2.1.4
3556-
"@lumino/keyboard": ^2.0.1
3557-
"@lumino/messaging": ^2.0.1
3558-
"@lumino/properties": ^2.0.1
3559-
"@lumino/signaling": ^2.1.2
3560-
"@lumino/virtualdom": ^2.0.1
3561-
checksum: 954fe066b0826cf00c019731bb3f70e635c63be4a0ce27f7573dbe6bd59e2154f511594b50e8f58f44877cf514084128c1e894ecbbbfd6e20d937e5cfb69ca8b
3562-
languageName: node
3563-
linkType: hard
3564-
3565-
"@lumino/widgets@npm:^2.5.0":
3451+
"@lumino/widgets@npm:^1.37.2 || ^2.3.1, @lumino/widgets@npm:^2.3.1, @lumino/widgets@npm:^2.3.2, @lumino/widgets@npm:^2.5.0":
35663452
version: 2.5.0
35673453
resolution: "@lumino/widgets@npm:2.5.0"
35683454
dependencies:
@@ -5941,10 +5827,10 @@ __metadata:
59415827
languageName: node
59425828
linkType: hard
59435829

5944-
"comlink@npm:^4.3.1, comlink@npm:^4.4.1":
5945-
version: 4.4.1
5946-
resolution: "comlink@npm:4.4.1"
5947-
checksum: 16d58a8f590087fc45432e31d6c138308dfd4b75b89aec0b7f7bb97ad33d810381bd2b1e608a1fb2cf05979af9cbfcdcaf1715996d5fcf77aeb013b6da3260af
5830+
"comlink@npm:^4.3.1, comlink@npm:^4.4.2":
5831+
version: 4.4.2
5832+
resolution: "comlink@npm:4.4.2"
5833+
checksum: 35313f26fdd78c202be21be49a7607f57e9e91963399b524676742ee0cf7db589be500d923ed0809b53f37996461186fb345bf867d93236be22bfae3cb7bd07e
59485834
languageName: node
59495835
linkType: hard
59505836

0 commit comments

Comments
 (0)