Bug 239289

Summary: Drop inefficient String::append() overloads
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Web Template FrameworkAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, achristensen, alecflett, andresg_22, apinheiro, beidson, benjamin, calvaris, cfleizach, changseok, cmarcelo, darin, dino, dmazzoni, eric.carlson, esprehn+autocc, ews-watchlist, fred.wang, galpeter, ggaren, glenn, gyuyoung.kim, hi, jamesr, jcraig, jdiggs, joepeck, jsbell, kangil.han, keith_miller, kondapallykalyan, luiz, mark.lam, mifenton, msaboff, pangle, pdr, philipj, saam, samuel_white, sam, simon.fraser, tonikitoo, toyoshim, tzagallo, webkit-bug-importer, yutak
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 239306    
Bug Blocks:    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
ews-feeder: commit-queue-
Patch none

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>