Bug 239289 - Drop inefficient String::append() overloads
Summary: Drop inefficient String::append() overloads
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on: 239306
Blocks:
  Show dependency treegraph
 
Reported: 2022-04-13 10:34 PDT by Chris Dumez
Modified: 2022-04-14 10:57 PDT (History)
47 users (show)

See Also:


Attachments
Patch (131.91 KB, patch)
2022-04-13 10:40 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (135.72 KB, patch)
2022-04-13 11:04 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (137.13 KB, patch)
2022-04-13 12:03 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (52.08 KB, patch)
2022-04-14 07:39 PDT, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.66 KB, patch)
2022-04-14 07:51 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2022-04-13 10:34:40 PDT
Drop inefficient String::append() overloads to push developers to use StringBuilder / makeString() instead.
Comment 1 Chris Dumez 2022-04-13 10:40:09 PDT
Created attachment 457545 [details]
Patch
Comment 2 Chris Dumez 2022-04-13 11:04:41 PDT
Created attachment 457547 [details]
Patch
Comment 3 Chris Dumez 2022-04-13 12:03:36 PDT
Created attachment 457553 [details]
Patch
Comment 4 Sam Weinig 2022-04-13 14:53:38 PDT
Comment on attachment 457553 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457553&action=review

> Source/WebCore/Modules/indexeddb/IDBKeyData.cpp:375
> +        result = makeString(StringView(result).left(147), "..."_s);

This hurts me but its just a logging string so I will not be overly upset.

> Source/WebCore/Modules/indexeddb/shared/IDBIndexInfo.cpp:65
> +    return makeString(indentString.toString(), "Index: ", m_name, " (", m_identifier, ") keyPath: ", WebCore::loggingString(m_keyPath), '\n');

This should probably be:

indentString.append("Index: ", m_name, " (", m_identifier, ") keyPath: ", WebCore::loggingString(m_keyPath), '\n');
return indentString.toString();

or just

makeString(WTF::Indentation<1> { indent }, "Index: ", m_name, " (", m_identifier, ") keyPath: ", WebCore::loggingString(m_keyPath), '\n');

> Source/WebCore/inspector/agents/InspectorDOMAgent.cpp:1776
> +            nodeValue = makeString(StringView(nodeValue).left(maxTextSize), ellipsisUChar);

We should probably be using ellipsisUChar everywhere we use "..." if we want to be good macOS citizens (don't ned to make that change now though).
Comment 5 Darin Adler 2022-04-13 14:59:40 PDT
Comment on attachment 457553 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=457553&action=review

Seems like the substring(0, ...) changes to left() are not closely related to removing String::append overloads. Just a separate change included in the same patch but not mention in the title.

And many of those are cases where left often allocates a new String. Some of them could be using StringView instead.

> Source/JavaScriptCore/runtime/IntlObject.cpp:961
> +        foundLocale = makeString(foundLocaleView.left(matcherResult.extensionIndex), supportedExtension.toString(), foundLocaleView.substring(matcherResult.extensionIndex));

Not clear how cheap StringBuilder::toString is. If it’s at all expensive, we could make makeString support StringBuilder directly without doing any memory allocation, although obviously that work need not be done in this patch.

> Source/WTF/wtf/text/StringBuilder.h:64
> +    void append(ASCIILiteral);

We need to move the model to where the set of things supported by StringBuilder are the same as the set supported by makeString without so much repeated code.

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:329
> +    LOG(IndexedDB, "IDBCursor::setGetResult - current key %s", getResult.keyData().loggingString().left(100).utf8().data());

Here’s one example I noticed before realizing the patter than the substring/left changes were following: Can this be done with StringView instead? Why allocate the truncated string just to use it to call utf8()?
Comment 6 Chris Dumez 2022-04-13 16:08:11 PDT
(In reply to Darin Adler from comment #5)
> Comment on attachment 457553 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=457553&action=review
> 
> Seems like the substring(0, ...) changes to left() are not closely related
> to removing String::append overloads. Just a separate change included in the
> same patch but not mention in the title.

Yes, I got a little too excited I think :) Splitting this part out into Bug 239306 and adopting more StringView in the process.
Comment 7 Darin Adler 2022-04-13 16:09:17 PDT
(In reply to Chris Dumez from comment #6)
> Yes, I got a little too excited I think :)

Oh, I understand, believe me!
Comment 8 Chris Dumez 2022-04-14 07:39:08 PDT
Created attachment 457625 [details]
Patch
Comment 9 Chris Dumez 2022-04-14 07:51:20 PDT
Created attachment 457626 [details]
Patch
Comment 10 EWS 2022-04-14 10:56:29 PDT
Committed r292879 (249649@main): <https://commits.webkit.org/249649@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457626 [details].
Comment 11 Radar WebKit Bug Importer 2022-04-14 10:57:16 PDT
<rdar://problem/91764586>