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
Re-evaluate JS-to-Wasm ASCII bypass of TextEncoder on Firefox Nightly #1776
Comments
CC @RReverser |
Hmm I might need to defer this to someone else as I'm working on something else now, but I think the difference was noticeable on V8 too, so fix in one engine doesn't necessarily fix it. I might be wrong and happy for someone to show otherwise by re-running benchmarks that were included in original PR. |
Using this patch on current master using today's Firefox nightly built from Built from https://hg.mozilla.org/mozilla-central/rev/19704452bd548d0c36d601d609cfcfe2c3e0caa2 and using these benchmarks sourced from this directory I'm getting:
|
@alexcrichton Nice! For what it's worth, my original benchmarks from the PR are still here: https://github.com/RReverser/wasm-bindgen-string-benches. Either way, can you please check and show results with Chrome as well? As stated in the original message, Firefox was already getting just 45% speed up from my original patch, whereas Chrome was getting 80%; I wonder if it still benefits from these changes. |
So these are something per second and, therefore, higher is better? I.e. the bypass is still faster than If so, the results are disappointing from my point of view. :-( Since these strings are literals and not the result of JavaScript programs putting them together by concatenation, etc., they don't end up testing rope issues at all. Also, testing round-tripping can be noisy, since Do you happen to know what the usage patterns are like? Do strings that get passed to Wasm usually originate from DOM API return values without further processing (not ropes). Or from arbitrary JS code (potentially ropes)? |
@RReverser I think this issue is largely about Firefox, so it's probably not worth checking Chrome until we think we want to change it for Firefox. Or at least that's what I'm personally gonna do! @hsivonen right yeah, these are operations/section where the higher numbers are better. And yeah these are showing that the current code is still faster than unconditionally calling As for usage patterns, I'm not really entirely sure myself. I think that usage is general enough though that there's not really a typical pattern, but rather there's a lot of different use cases for where strings come from and such. |
I'm going to close this since the numbers above I think show that this is still a beneficial optimization to have. |
Revision 57b1a57 added an ASCII bypass of
TextEncoder
for passing strings from JS to Wasm. From my perspective as aTextEncoder
developer, the need to add such a special case is a performance bug on theTextEncoder
side. Therefore, I madeTextEncoder.encodeInto
faster in Firefox Nightly especially for ASCII strings.Notably, for ropes deeper than one level,
charCodeAt
linearizes the string in Firefox butTextEncoder
no longer does. If the string is a more than one-level concatenation of relatively long ASCII pieces, I expectTextEncoder.encodeInto
to now outperformwasm-bindgen
's manual ASCII path.Could you, please, re-run the benchmarks that motivated the manual
TextDecoder
bypass inwasm-bindgen
in Firefox Nightly to see if the manual by-pass can be removed or if the manual bypass should be limited to tiny strings (where JIT inlining ofcharCodeAt
may still be a win)?(FWIW, there's also a similar
TextDecoder
optimization in flight for Firefox.)The text was updated successfully, but these errors were encountered: