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

Add fast path to JSStringJoiner::join() when there is only one string in the vector #11970

Merged
merged 1 commit into from
Mar 26, 2023

Conversation

@cdumez cdumez requested a review from a team as a code owner March 25, 2023 16:30
@cdumez cdumez self-assigned this Mar 25, 2023
@cdumez cdumez added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Mar 25, 2023
@cdumez
Copy link
Contributor Author

cdumez commented Mar 25, 2023

A/B testing says this is a 0.72% progression (98% confidence) on Speedometer on M1 and 0.7% progression on JetStream (98% confidence).

@Jarred-Sumner
Copy link

nice

inline JSValue JSStringJoiner::join(JSGlobalObject* globalObject)
{
if (m_strings.size() == 1)
return jsString(globalObject->vm(), m_strings[0].view.toString());
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s correct. But:

  1. 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
  2. if the string view’s length is smaller than the underlying string, we could use substringSharingImpl to create a new StringImpl 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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@cdumez cdumez force-pushed the 254463_JSStringJointer_join branch from 960ebac to 96b098e Compare March 25, 2023 21:12
@cdumez cdumez added the merge-queue Applied to send a pull request to merge-queue label Mar 26, 2023
@cdumez
Copy link
Contributor Author

cdumez commented Mar 26, 2023

Will land as-is for now since this patch tested as a progression. I'll look into refining in a follow-up.

@cdumez cdumez added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merge-queue Applied to send a pull request to merge-queue labels Mar 26, 2023
… 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
@webkit-commit-queue
Copy link
Collaborator

Committed 262129@main (47cdb9c): https://commits.webkit.org/262129@main

Reviewed commits have been landed. Closing PR #11970 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 47cdb9c into WebKit:main Mar 26, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
5 participants