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

Setting the value of a textarea is much slower in WebKit than it is in Chromium #6411

Conversation

darinadler
Copy link
Member

@darinadler darinadler commented Nov 11, 2022

610bbdb

Setting the value of a textarea is much slower in WebKit than it is in Chromium
https://bugs.webkit.org/show_bug.cgi?id=247739
rdar://problem/102218029

Reviewed by Alexey Proskuryakov.

These changes make the micro-benchmark of setting the text of a textarea about 4x faster.

* Source/WTF/wtf/text/StringView.cpp:
(WTF::makeStringBySimplifyingNewLinesSlowCase): Added. Implements a faster algorithm for
standardizing line endings as opposed to making two passes through the string.

* Source/WTF/wtf/text/StringView.h:
(WTF::makeStringBySimplifyingNewLines): Added a high-speed check for '\r' characters before doing
the slower algorithm to standardize line separators. Most strings won't have any at all, and none
of the ones in the benchmark do.

Canonical link: https://commits.webkit.org/256596@main

2d6c86c

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe   πŸ›  πŸ§ͺ win
βœ… πŸ›  ios-sim βœ… πŸ›  mac-debug βœ… πŸ›  gtk   πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ gtk-wk2
  πŸ§ͺ api-ios βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-gtk
  πŸ›  πŸ§ͺ jsc βœ… πŸ›  tv   πŸ§ͺ mac-wk1 βœ… πŸ›  jsc-armv7
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ jsc-armv7-tests
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch   πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ›  jsc-mips
βœ… πŸ›  watch-sim βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ jsc-mips-tests

@darinadler darinadler self-assigned this Nov 11, 2022
@darinadler darinadler added Forms For bugs specific to form elements (checkboxes, buttons, text fields, etc.) Safari Technology Preview labels Nov 11, 2022
@@ -447,6 +447,35 @@ int codePointCompare(StringView lhs, StringView rhs)
return codePointCompare(lhs.characters16(), lhs.length(), rhs.characters16(), rhs.length());
}

template<typename CharacterType> static String makeStringBySimplifyingNewLinesSlowCase(const String& string, unsigned firstCarriageReturn)
{
unsigned length = string.length();
Copy link
Contributor

Choose a reason for hiding this comment

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

May be worth ASSERTing some sanity for firstCarriageReturn. Chances are this function is so much of a special case that no one will ever try to misuse it, so not feeling strongly about the need for sanity checks.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel comfortable leaving this as is.

auto result = String::createUninitialized(length, resultCharacters);
memcpy(resultCharacters, characters, firstCarriageReturn * sizeof(CharacterType));
for (unsigned i = firstCarriageReturn; i < length; ++i) {
if (characters[i] != '\r')
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a slight concern about whether the existing function implemented the correct algorithm. Do we know for certain what normalization is supposed to be done? I've seen some weird newline combinations in the past (\n\r, \r\r\n are treated as a single newline by some software).

Copy link
Member Author

Choose a reason for hiding this comment

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

I am certain the function is doing the correct normalization. I researched this originally and still remember learning this was exactly what is needed.

@darinadler darinadler added the merge-queue Applied to send a pull request to merge-queue label Nov 12, 2022
…n Chromium

https://bugs.webkit.org/show_bug.cgi?id=247739
rdar://problem/102218029

Reviewed by Alexey Proskuryakov.

These changes make the micro-benchmark of setting the text of a textarea about 4x faster.

* Source/WTF/wtf/text/StringView.cpp:
(WTF::makeStringBySimplifyingNewLinesSlowCase): Added. Implements a faster algorithm for
standardizing line endings as opposed to making two passes through the string.

* Source/WTF/wtf/text/StringView.h:
(WTF::makeStringBySimplifyingNewLines): Added a high-speed check for '\r' characters before doing
the slower algorithm to standardize line separators. Most strings won't have any at all, and none
of the ones in the benchmark do.

Canonical link: https://commits.webkit.org/256596@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/Setting-the-value-of-a-textarea-is-much-slower-in-WebKit-than-it-is-in-Chromium branch from 2d6c86c to 610bbdb Compare November 12, 2022 01:09
@webkit-commit-queue
Copy link
Collaborator

Committed 256596@main (610bbdb): https://commits.webkit.org/256596@main

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

@webkit-early-warning-system webkit-early-warning-system merged commit 610bbdb into WebKit:main Nov 12, 2022
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Nov 12, 2022
@darinadler darinadler deleted the eng/Setting-the-value-of-a-textarea-is-much-slower-in-WebKit-than-it-is-in-Chromium branch November 13, 2022 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Forms For bugs specific to form elements (checkboxes, buttons, text fields, etc.)
Projects
None yet
4 participants