Skip to content
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

Have physical equality inspect Javascript objects #25

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

OlivierNicole
Copy link
Collaborator

Currently in wasm, physical equality behaves differently from in Javascript: Javascript objects are boxed, and non-equality of the pointers causes the values to be physically not equal. This can be an issue for some folks who rely on the JS-object-inspecting semantics of physical equality to implement things such as memoizing.

This restores the fact that physical equality inspects Javascript objects. Other values are unaffected. This entails to pay an additional cost of between one and two Wasm runtime type tests in physical equality. A quick benchmark performing a few million (==) in an array of integers show a slowdown of 20~25 %. Since typical programs should perform physical equality much less frequently, we expect the overhead to be in the noise in practice.

That being said, we may want to make this behaviour opt-in using a flag.

Currently in wasm, physical equality behaves differently from in
Javascript: Javascript objects are boxed, and non-equality of the
pointers causes the values to be physically not equal. This can be an
issue for some folks who rely on the JS-object-inspecting semantics of
physical equality to implement things such as memoizing.

This restores the fact that physical equality inspects Javascript
objects. Other values are unaffected. This entails to pay an additional
cost of between one and two Wasm runtime type tests in physical
equality. A quick benchmark performing a few million `(==)` in an array
of integers show a slowdown of 20~25 %. Since typical programs should
perform physical equality much less frequently, we expect the overhead
to be in the noise in practice.

That being said, we may want to make this behaviour opt-in using a flag.

Co-authored-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
@vouillon
Copy link
Collaborator

I think I'm going to merge this PR as is. We'll add an opt out flag later if necessary. Could you make sure that all the files are properly formatted?

@OlivierNicole
Copy link
Collaborator Author

It should be now.

@vouillon vouillon merged commit 69824ed into ocaml-wasm:main Mar 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants