reearth / quickjs-emscripten-sync

Provides a way to sync objects between browser and QuickJS
MIT License
62 stars 7 forks source link

chore: experimental flag to solve errors when functions are repeatedly created #21

Closed rot1024 closed 1 year ago

rot1024 commented 1 year ago

This PR is a tentative solution to #20

The existing QuickJSContext has a problem that after about 3000~10000 calls to newFunction to create a function, the fnMap in the context is exhausted and function creation fails.

So, although a bit aggressive, wrap newFunction and override it so that newFunction is actually called only once. This can be done in principle by increasing the counter each time a new VmFunctionImplementation is received, storing it in a map, embedding only the ID in the VM-side function, and calling it from the map when it is called.

All unit tests passed without modification, but since QuickJSContext is wrapped to change its behavior, this feature will not be fully usable in a production environment until it is tried. Therefore, we have implemented this feature so that it will not work without the experimental flag enabled.

codecov[bot] commented 1 year ago

Codecov Report

Base: 97.34% // Head: 97.59% // Increases project coverage by +0.24% :tada:

Coverage data is based on head (195472b) compared to base (402c146). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #21 +/- ## ========================================== + Coverage 97.34% 97.59% +0.24% ========================================== Files 21 22 +1 Lines 1584 1665 +81 Branches 373 392 +19 ========================================== + Hits 1542 1625 +83 + Misses 42 40 -2 ``` | [Impacted Files](https://codecov.io/gh/reearth/quickjs-emscripten-sync/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth) | Coverage Δ | | |---|---|---| | [src/contextex.ts](https://codecov.io/gh/reearth/quickjs-emscripten-sync/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth#diff-c3JjL2NvbnRleHRleC50cw==) | `100.00% <100.00%> (ø)` | | | [src/index.ts](https://codecov.io/gh/reearth/quickjs-emscripten-sync/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth#diff-c3JjL2luZGV4LnRz) | `93.11% <100.00%> (+0.35%)` | :arrow_up: | | [src/vmmap.ts](https://codecov.io/gh/reearth/quickjs-emscripten-sync/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth#diff-c3JjL3ZtbWFwLnRz) | `99.23% <100.00%> (ø)` | | | [src/wrapper.ts](https://codecov.io/gh/reearth/quickjs-emscripten-sync/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth#diff-c3JjL3dyYXBwZXIudHM=) | `98.98% <100.00%> (+0.06%)` | :arrow_up: | | [src/marshal/custom.ts](https://codecov.io/gh/reearth/quickjs-emscripten-sync/pull/21?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth#diff-c3JjL21hcnNoYWwvY3VzdG9tLnRz) | `94.44% <0.00%> (+2.77%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reearth)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.