-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add fast path to JSStringJoiner::join() when there is only one string in the vector #11970
Add fast path to JSStringJoiner::join() when there is only one string in the vector #11970
Conversation
EWS run on previous version of this PR (hash 960ebac) |
A/B testing says this is a 0.72% progression (98% confidence) on Speedometer on M1 and 0.7% progression on JetStream (98% confidence). |
nice |
inline JSValue JSStringJoiner::join(JSGlobalObject* globalObject) | ||
{ | ||
if (m_strings.size() == 1) | ||
return jsString(globalObject->vm(), m_strings[0].view.toString()); |
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.
Why doesn't this use the underlying string if present? Seems that doing that could avoid allocating a new StringImpl
in some cases. Maybe those aren't common enough.
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.
I assumed the string view might point to only part of the underlying string? I am not very familiar with this code.
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.
Thatβs correct. But:
- if the lengths are equal, the underlying string can be used as is β I think this is a common case and the optimization of not allocating any memory for a
StringImpl
would be significant - if the string viewβs length is smaller than the underlying string, we could use
substringSharingImpl
to create a newStringImpl
that is small and shares the characters, but that may be a more difficult tradeoff since we could keep a large string alive, and may not be as common a case
I was really thinking of (1) above, and if itβs common enough it might lead to a bigger performance win.
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.
Thanks for the clarification. I'll see if we can get a bigger win.
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.
You are right that (1) is the common case. 99.1% of the cases in Speedometer where m_strings has a length of 1 in fact. I'll do some A/B testing on the bots.
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.
Hmm, I tried the following patch (https://pastebin.com/Nwacq8mF) but A/B testing says this is no longer a progression. Weird.
960ebac
to
96b098e
Compare
Will land as-is for now since this patch tested as a progression. I'll look into refining in a follow-up. |
β¦ in the vector https://bugs.webkit.org/show_bug.cgi?id=254463 Reviewed by Darin Adler. * Source/JavaScriptCore/runtime/JSStringJoiner.cpp: (JSC::JSStringJoiner::joinSlow): (JSC::JSStringJoiner::join): Deleted. * Source/JavaScriptCore/runtime/JSStringJoiner.h: (JSC::JSStringJoiner::join): Canonical link: https://commits.webkit.org/262129@main
96b098e
to
47cdb9c
Compare
Committed 262129@main (47cdb9c): https://commits.webkit.org/262129@main Reviewed commits have been landed. Closing PR #11970 and removing active labels. |
47cdb9c
96b098e
π§ͺ api-iosπ π§ͺ merge