-
Notifications
You must be signed in to change notification settings - Fork 194
runtime: fix useArrowFunction and noArguments #1682
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
This PR looks like it contains some formatting changes (using arrow functions) and also rewrites some of the most foundational primitives in the jsoo runtime. Could you split these up so that that latter can be thouroughly reviewed and benchmarked? |
Also, why are you interested in using arrow functions and avoid using |
1358f63
to
68b76ed
Compare
Context Differences
The arrow function has no binding processing, so you might see some performance improvement in this case. That said, you should not see much difference in general. |
68b76ed
to
03d50f8
Compare
Does this ever come up in jsoo? |
@TyOverby See |
03d50f8
to
b284944
Compare
|
The rest parameter and arguments show almost no difference in the benchmark results for major browsers: https://jsben.ch/BQEVR |
But Chrome is converting it to an array under the hood too. I benchmarked this a few years ago and found that using the spread operator had no impact on speed |
The rest parameter seems to be faster for many arguments: https://jsben.ch/Krmit |
It's true, but it has a certain advantage here because it simplifies the runtime code. If we are going to introduce const/let, ES6 is required, and if we don't see any performance regression, I think we can consider this kind of change positively. |
On my machine at least, the new code is reliably 4% slower.
I think we should prioritize calling functions that have a small number of arguments, as small-arity functions are more common in OCaml than functions with 100+ parameters.
I modified your benchmark so that the arrays aren't empty, and to do some fast computation with them instead of logging (logging is slow, and mucks with benchmark results), and this new benchmark shows that even for 100-parameter calls, the old method is twice as fast (on Chrome at least) than using the new syntax: https://jsben.ch/sGBgk |
I'm seeing a strange result 🤔 (I'm also on the latest Chrome btw) ![]() |
I ran it on the latest Chrome with Apple Silicon. What's your environment? |
Latest Chrome x86-64 |
b284944
to
7ea59a4
Compare
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.
Copilot reviewed 5 out of 18 changed files in this pull request and generated no suggestions.
Files not reviewed (13)
- biome.json: Language not supported
- runtime/blake2.js: Evaluated as low risk
- runtime/graphics.js: Evaluated as low risk
- runtime/effect.js: Evaluated as low risk
- runtime/backtrace.js: Evaluated as low risk
- runtime/gc.js: Evaluated as low risk
- runtime/fs_node.js: Evaluated as low risk
- runtime/zstd.js: Evaluated as low risk
- runtime/md5.js: Evaluated as low risk
- runtime/weak.js: Evaluated as low risk
- runtime/sys.js: Evaluated as low risk
- runtime/marshal.js: Evaluated as low risk
- runtime/str.js: Evaluated as low risk
7ea59a4
to
1353460
Compare
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.
Copilot reviewed 5 out of 17 changed files in this pull request and generated no suggestions.
Files not reviewed (12)
- biome.json: Language not supported
- runtime/js/io.js: Evaluated as low risk
- runtime/js/jslib.js: Evaluated as low risk
- runtime/js/graphics.js: Evaluated as low risk
- runtime/js/gc.js: Evaluated as low risk
- runtime/js/backtrace.js: Evaluated as low risk
- runtime/js/effect.js: Evaluated as low risk
- runtime/js/zstd.js: Evaluated as low risk
- runtime/js/fs_node.js: Evaluated as low risk
- runtime/js/blake2.js: Evaluated as low risk
- runtime/js/md5.js: Evaluated as low risk
- runtime/js/marshal.js: Evaluated as low risk
@smorimoto, I think it would be good to split the two changes as suggested above so that they can be tested independently. |
To fix the noArguments, you need the arrow function, and to fix the useArrowFunction, you need to remove the arguments... |
I don't see the relation, sorry. I would expect that only spread is needed to replace usage of |
After asking for the PR to be split up, I did the benchmarking which has me pretty confident that the change should instead be abandoned, so I don’t want anyone doing the extra work of splitting the feature up if it’s not going to be merged. |
Which part is slower ? |
I suspect it’s the … args syntax, but I don’t know for sure. |
@TyOverby, Have you run more that just micro benchmarks ? Were you able to see differences with real applications ? |
I haven’t run this on any real applications because we aren’t easily able to pull in jsoo branches until wasm is merged. However, i think that microbenchmarks are sufficient to reject what is effectively a code formatting change |
Except this PR is not only about formatting. Also, I've been tricked many times by javascript micro benchmarks because real program would sometime show opposite result. The last one was #1647 that I ended up reverting. |
What is the purpose of the PR then? Did some user of Js_of_ocaml need the runtime javascript to be more “modern” for some reason? FWIW, I find the new style of code in this PR to be harder to read than the original, so without a good reason to do it (like performance), i’m pretty opposed |
This PR will not be merge in its current state (You and I both suggested to split it up). I've extracted and reworked part of it in #1740 and I personally find the code much more digest in its new form. |
Benchmarking with CAMLBOY is probably useful: https://github.com/linoscope/CAMLBOY |
Signed-off-by: Sora Morimoto <[email protected]>
1353460
to
98dd8c0
Compare
5.8.2First Attempt
Second attempt
This PRFirst Attempt
Second attempt
|
The more I look at it the more I dislike the systematic use of arrow functions. I think we should use them only when it improves readability significantly. If one show that it improves performance, we could perform the translation automatically on the fly. I believe we already have code for that. |
I'm going to close this one in favor of #1740. I don't really know what do to with the systematic use of arrow. Let reconsider later maybe |
OK |
Note: this partially introduces ES6!