RESOLVED FIXED138619
Speed up HTMLTextFormControlElement::setInnerTextValue() a bit
https://bugs.webkit.org/show_bug.cgi?id=138619
Summary Speed up HTMLTextFormControlElement::setInnerTextValue() a bit
Chris Dumez
Reported 2014-11-11 11:55:18 PST
Speed up HTMLTextFormControlElement::setInnerTextValue() a bit by: - Not doing a virtual isTextFormControl() call. Relying on innerTextElement() not returning null is sufficient - Caching the result of innerTextElement() instead of repeatedly calling that virtual function - De-virtualizing setFormControlValueMatchesRenderer() / formControlValueMatchesRenderer() as these are never overridden. - Moving the code constructing the innerTextValue from a TextControlInnerTextElement from innerTextValue() to a new innerTextValueFrom(TextControlInnerTextElement&) inline and call this new function from setInnerTextValue() to avoid calling innerTextElement() again making sure it is non-null - Do the tree traversal from innerTextElement's firstChild instead of from innerTextElement. The innerTextElement is a TextControlInnerTextElement. Therefore, it cannot be an HTMLBRElement or a Text node.
Attachments
Patch (6.35 KB, patch)
2014-11-11 11:59 PST, Chris Dumez
no flags
Patch (6.81 KB, patch)
2014-11-12 09:16 PST, Chris Dumez
no flags
Patch (6.78 KB, patch)
2014-11-12 11:41 PST, Chris Dumez
no flags
Chris Dumez
Comment 1 2014-11-11 11:59:24 PST
Darin Adler
Comment 2 2014-11-11 20:21:49 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review > Source/WebCore/html/HTMLTextFormControlElement.cpp:524 > +static inline String finishText(StringBuilder& result) Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? > Source/WebCore/html/HTMLTextFormControlElement.cpp:533 > +static inline String innerTextValueFrom(TextControlInnerTextElement& innerText) Do we really need to inline this? It seems like there's enough code here that the function call overhead is not excessive.
Chris Dumez
Comment 3 2014-11-11 20:30:37 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review >> Source/WebCore/html/HTMLTextFormControlElement.cpp:524 >> +static inline String finishText(StringBuilder& result) > > Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? How about void stripTrailingNewLineCharacter(StringBuilder&) ? and move the result.toString() to the callers? It is clearer IMHO than "finish*". Finish doesn't really tell you what the function does. >> Source/WebCore/html/HTMLTextFormControlElement.cpp:533 >> +static inline String innerTextValueFrom(TextControlInnerTextElement& innerText) > > Do we really need to inline this? It seems like there's enough code here that the function call overhead is not excessive. Hmm. The cost of iterating through the descendants and construct the String probably makes the cost of the function call negligible. I marked it as inline because this code used to be inlined in innerTextValue() and I wanted to make sure I did not cause that one to regress while trying to make setInnerTextValue() faster. I will check if I see any perf difference, if there isn't then I'll drop the inline.
Chris Dumez
Comment 4 2014-11-11 20:31:24 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review >>> Source/WebCore/html/HTMLTextFormControlElement.cpp:524 >>> +static inline String finishText(StringBuilder& result) >> >> Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? > > How about void stripTrailingNewLineCharacter(StringBuilder&) ? and move the result.toString() to the callers? It is clearer IMHO than "finish*". Finish doesn't really tell you what the function does. strip or trim, hard for me to tell which one would be better here.
Darin Adler
Comment 5 2014-11-12 09:00:16 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review >>>> Source/WebCore/html/HTMLTextFormControlElement.cpp:524 >>>> +static inline String finishText(StringBuilder& result) >>> >>> Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? >> >> How about void stripTrailingNewLineCharacter(StringBuilder&) ? and move the result.toString() to the callers? It is clearer IMHO than "finish*". Finish doesn't really tell you what the function does. > > strip or trim, hard for me to tell which one would be better here. I think I included to the toString originally because I was trying to share as much code as possible. I think that "strip", "trim", or "remove" would all be OK.
Darin Adler
Comment 6 2014-11-12 09:00:46 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review >>>>> Source/WebCore/html/HTMLTextFormControlElement.cpp:524 >>>>> +static inline String finishText(StringBuilder& result) >>>> >>>> Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? >>> >>> How about void stripTrailingNewLineCharacter(StringBuilder&) ? and move the result.toString() to the callers? It is clearer IMHO than "finish*". Finish doesn't really tell you what the function does. >> >> strip or trim, hard for me to tell which one would be better here. > > I think I included to the toString originally because I was trying to share as much code as possible. > > I think that "strip", "trim", or "remove" would all be OK. But it’s "newline character", not "new line character", so it should be stripTrailingNewlineCharacter.
Darin Adler
Comment 7 2014-11-12 09:01:09 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review >>>>>> Source/WebCore/html/HTMLTextFormControlElement.cpp:524 >>>>>> +static inline String finishText(StringBuilder& result) >>>>> >>>>> Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? >>>> >>>> How about void stripTrailingNewLineCharacter(StringBuilder&) ? and move the result.toString() to the callers? It is clearer IMHO than "finish*". Finish doesn't really tell you what the function does. >>> >>> strip or trim, hard for me to tell which one would be better here. >> >> I think I included to the toString originally because I was trying to share as much code as possible. >> >> I think that "strip", "trim", or "remove" would all be OK. > > But it’s "newline character", not "new line character", so it should be stripTrailingNewlineCharacter. I think stripTrailingNewline would be a fine name.
Darin Adler
Comment 8 2014-11-12 09:01:53 PST
Comment on attachment 241366 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=241366&action=review >>>>>>> Source/WebCore/html/HTMLTextFormControlElement.cpp:524 >>>>>>> +static inline String finishText(StringBuilder& result) >>>>>> >>>>>> Now that you moved this function, I noticed that it does not have a great name. Maybe finishInnerTextValue? >>>>> >>>>> How about void stripTrailingNewLineCharacter(StringBuilder&) ? and move the result.toString() to the callers? It is clearer IMHO than "finish*". Finish doesn't really tell you what the function does. >>>> >>>> strip or trim, hard for me to tell which one would be better here. >>> >>> I think I included to the toString originally because I was trying to share as much code as possible. >>> >>> I think that "strip", "trim", or "remove" would all be OK. >> >> But it’s "newline character", not "new line character", so it should be stripTrailingNewlineCharacter. > > I think stripTrailingNewline would be a fine name. And inlining the function seems a little strange. The process of building the string is doing memory allocation, so function call overhead should be negligible by comparison; code sharing would be better.
Chris Dumez
Comment 9 2014-11-12 09:16:41 PST
Chris Dumez
Comment 10 2014-11-12 09:17:16 PST
Thanks, I renamed to stripTrailingNewline() and dropped the inline.
Chris Dumez
Comment 11 2014-11-12 11:41:47 PST
WebKit Commit Bot
Comment 12 2014-11-12 12:07:54 PST
Comment on attachment 241435 [details] Patch Clearing flags on attachment: 241435 Committed r176030: <http://trac.webkit.org/changeset/176030>
WebKit Commit Bot
Comment 13 2014-11-12 12:07:59 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.