-
Notifications
You must be signed in to change notification settings - Fork 62
Fix BigInt serialization through web worker postMessage #2071
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
Conversation
BigInteger.js objects lose their prototype methods (like .lt()) when passed through postMessage's structured clone algorithm. This caused crashes when displaying large integers in evaluation results. Add BigIntShim module that serializes BigInts to tagged objects before postMessage and reconstructs them using zarith's jsoo_z_of_js_string_base after receiving. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #2071 +/- ##
==========================================
+ Coverage 50.47% 50.49% +0.02%
==========================================
Files 229 229
Lines 25189 25188 -1
==========================================
+ Hits 12713 12719 +6
+ Misses 12476 12469 -7
🚀 New features to boost your workflow:
|
Replace the O(n) BigIntShim serialization workaround with a vendored zarith_stubs_js runtime that uses native JavaScript BigInt instead of BigInteger.js. Native BigInt survives structured clone (postMessage), eliminating the need for manual serialization. - Vendor zarith_stubs_js v0.17.0 runtime.js (uses native BigInt) - Add setup-zarith Makefile target to install vendored runtime - Remove BigIntShim.re and its usage in WorkerClient/WorkerServer - Update CI workflow to run setup-zarith before build - Add docs/bigint-webworker-fix.md explaining the approach Co-Authored-By: Claude Opus 4.5 <[email protected]>
Clarify that it's js_of_ocaml-compiler (not js_of_ocaml itself) that has the ocaml < 5.2 constraint in versions before 5.7.0. Co-Authored-By: Claude Opus 4.5 <[email protected]>
The 'different BigInt library' option was misleading since zarith is the standard OCaml library and the issue was the JS backend, not zarith itself. The Comlink option was an obscure reference that added confusion. Co-Authored-By: Claude Opus 4.5 <[email protected]>
The constraint issue is specific to bonsai v0.17.0 on opam. The master branch has been updated to require js_of_ocaml >= 6.0.0, so a future release will resolve this. Co-Authored-By: Claude Opus 4.5 <[email protected]>
cyrus-
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- licensing of the vendored library
|
update the PR description |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
The vendored file from zarith_stubs_js v0.17.0 was missing its license. Added the MIT license header from Jane Street as required for proper attribution. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
@cyrus- (MIT) license added, PR description changed |
Closes #2066
BigInteger.js objects lose their prototype methods (like .lt()) when passed through postMessage's structured clone algorithm. This caused crashes when displaying large integers in evaluation results. Starting in v0.17.0,
zarith_stubs_jsswitched to using native JavaScriptBigIntinstead of BigInteger.js. NativeBigIntis a primitive type that fully survives structured clone. However, we cannot simply upgrade to zarith_stubs_js v0.17.0 due to versioning issues described inbigint-webworker-fix.md, so instead for now we'll vendor theruntime.jsfrom zarith_stubs_js v0.17.0 and copy it into the opam switch at build time.