WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
81214
[Performance] Optimize innerHTML and outerHTML
https://bugs.webkit.org/show_bug.cgi?id=81214
Summary
[Performance] Optimize innerHTML and outerHTML
Kentaro Hara
Reported
2012-03-15 06:30:14 PDT
Created
attachment 132034
[details]
Performance test We can optimize the performance of innerHTML and outerHTML more. The performance test is attached.
Attachments
Performance test
(115.71 KB, text/html)
2012-03-15 06:30 PDT
,
Kentaro Hara
no flags
Details
Patch
(23.28 KB, patch)
2012-03-15 06:32 PDT
,
Kentaro Hara
no flags
Details
Formatted Diff
Diff
Patch
(13.38 KB, patch)
2012-03-15 17:33 PDT
,
Kentaro Hara
no flags
Details
Formatted Diff
Diff
Patch
(13.96 KB, patch)
2012-03-15 18:32 PDT
,
Kentaro Hara
no flags
Details
Formatted Diff
Diff
patch for landing
(13.89 KB, patch)
2012-03-15 23:23 PDT
,
Kentaro Hara
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Kentaro Hara
Comment 1
2012-03-15 06:32:54 PDT
Created
attachment 132035
[details]
Patch
Kentaro Hara
Comment 2
2012-03-15 06:34:25 PDT
Comment on
attachment 132035
[details]
Patch The uploaded patch makes innerHTML and outerHTML 2.4 times faster. Since the patch is doing too many things, I will land it step by step. Comments are appreciated.
Adam Barth
Comment 3
2012-03-15 11:05:42 PDT
Very impressive.
Alexey Proskuryakov
Comment 4
2012-03-15 11:05:54 PDT
Does this speed up any widely recognized benchmark? If a change only improves a synthetic benchmark made just for it, then it may not be worth the code churn.
Kentaro Hara
Comment 5
2012-03-15 15:26:42 PDT
(In reply to
comment #4
)
> Does this speed up any widely recognized benchmark? If a change only improves a synthetic benchmark made just for it, then it may not be worth the code churn.
I couldn't find existing benchmarks that test innerHTML. But the attached performance benchmark tests body.innerHTML for 3000 lines of HTML, which is copied from Dromaeo/dom-attr.html. Thus I think the performance impact will be practical.
Ojan Vafai
Comment 6
2012-03-15 15:29:09 PDT
Patch looks great. The new code looks considerably simpler and more maintainable too!
Kentaro Hara
Comment 7
2012-03-15 17:33:40 PDT
Created
attachment 132161
[details]
Patch
Tony Chang
Comment 8
2012-03-15 17:56:02 PDT
Comment on
attachment 132161
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=132161&action=review
> Source/WebCore/editing/MarkupAccumulator.cpp:302 > - result.append("<!DOCTYPE "); > + result.append("<!DOCTYPE ", 10);
I would pull these out into const char* variables and use WTF_ARRAY_LENGTH instead of hard coding the lengths.
Adam Barth
Comment 9
2012-03-15 18:05:15 PDT
+rniwa for fun with MarkupAccumulator.cpp.
Kentaro Hara
Comment 10
2012-03-15 18:18:37 PDT
(In reply to
comment #8
)
> > Source/WebCore/editing/MarkupAccumulator.cpp:302 > > - result.append("<!DOCTYPE "); > > + result.append("<!DOCTYPE ", 10); > > I would pull these out into const char* variables and use WTF_ARRAY_LENGTH instead of hard coding the lengths.
tony: It seems we cannot call WTF_ARRAY_LENGTH for char* array... (without a hack in StdLibExtras.h) third_party/WebKit/Source/WebCore/editing/MarkupAccumulator.cpp: In static member function 'static void WebCore::MarkupAccumulator::appendComment(WTF::StringBuilder&, const WTF::String&)': third_party/WebKit/Source/WebCore/editing/MarkupAccumulator.cpp:293: error: no matching function for call to 'ArrayLengthHelperFunction(const char*&)' third_party/WebKit/Source/WebCore/editing/MarkupAccumulator.cpp:296: error: no matching function for call to 'ArrayLengthHelperFunction(const char*&)'
Tony Chang
Comment 11
2012-03-15 18:22:33 PDT
(In reply to
comment #10
)
> (In reply to
comment #8
) > > > Source/WebCore/editing/MarkupAccumulator.cpp:302 > > > - result.append("<!DOCTYPE "); > > > + result.append("<!DOCTYPE ", 10); > > > > I would pull these out into const char* variables and use WTF_ARRAY_LENGTH instead of hard coding the lengths. > > tony: It seems we cannot call WTF_ARRAY_LENGTH for char* array... (without a hack in StdLibExtras.h)
Sorry, you can do: const char Doctype[] = "<!DOCTYPE "; WTF_ARRAY_LENGTH(DocType) should work.
Adam Barth
Comment 12
2012-03-15 18:24:53 PDT
> const char Doctype[] = "<!DOCTYPE "; > WTF_ARRAY_LENGTH(DocType) should work.
^^^ WTF_ARRAY_LENGTH(DocType) - 1 :)
Kentaro Hara
Comment 13
2012-03-15 18:32:11 PDT
Created
attachment 132172
[details]
Patch
Kentaro Hara
Comment 14
2012-03-15 18:33:27 PDT
(In reply to
comment #12
)
> > const char Doctype[] = "<!DOCTYPE "; > > WTF_ARRAY_LENGTH(DocType) should work. > > ^^^ WTF_ARRAY_LENGTH(DocType) - 1 :)
Fixed. Thanks. I confirmed no performance difference between 'WTF_ARRAY_LENGTH(DocType) - 1' and hard-coding '10'.
Ryosuke Niwa
Comment 15
2012-03-15 21:11:06 PDT
Yay, you're doing my work (making them faster was on my OKRs).
Kentaro Hara
Comment 16
2012-03-15 21:19:31 PDT
Comment on
attachment 132172
[details]
Patch The patch passed all ews-bots. If the change looks ok, would anyone r+ it?
Adam Barth
Comment 17
2012-03-15 21:39:52 PDT
Comment on
attachment 132172
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=132172&action=review
The old code looks kind of silly after this patch. :)
> Source/WebCore/editing/MarkupAccumulator.cpp:156 > void MarkupAccumulator::concatenateMarkup(StringBuilder& result)
This function appears unused. Perhaps we can remove it?
> Source/WebCore/editing/MarkupAccumulator.h:81 > static size_t totalLength(const Vector<String>&);
Does this function have any more callers? Perhaps we can remove it.
Kentaro Hara
Comment 18
2012-03-15 21:41:41 PDT
(In reply to
comment #17
)
> > Source/WebCore/editing/MarkupAccumulator.cpp:156 > > void MarkupAccumulator::concatenateMarkup(StringBuilder& result) > > This function appears unused. Perhaps we can remove it? > > > Source/WebCore/editing/MarkupAccumulator.h:81 > > static size_t totalLength(const Vector<String>&); > > Does this function have any more callers? Perhaps we can remove it.
We cannot remove them because they are still used by markup.cpp. We should improve markup.cpp later.
Ryosuke Niwa
Comment 19
2012-03-15 21:44:30 PDT
Comment on
attachment 132172
[details]
Patch The patch looks great to me as well
Ryosuke Niwa
Comment 20
2012-03-15 21:44:39 PDT
The patch looks great to me as well
Alexey Proskuryakov
Comment 21
2012-03-15 21:53:48 PDT
Comment on
attachment 132172
[details]
Patch Why is this using WTF_ARRAY_LENGTH and not just sizeof? Size of char is guaranteed to be 1, we're not winning anything with fancy macros.
Kentaro Hara
Comment 22
2012-03-15 21:58:39 PDT
(In reply to
comment #21
)
> (From update of
attachment 132172
[details]
) > Why is this using WTF_ARRAY_LENGTH and not just sizeof? Size of char is guaranteed to be 1, we're not winning anything with fancy macros.
I guess either is OK, WTF_ARRAY_LENGTH is just an alias of sizeof in this case. As far as I see the code around, it seems we are likely to use WTF_ARRAY_LENGTH (instead of sizeof) since we do not need to care types.
Ryosuke Niwa
Comment 23
2012-03-15 22:26:20 PDT
(In reply to
comment #21
)
> (From update of
attachment 132172
[details]
) > Why is this using WTF_ARRAY_LENGTH and not just sizeof? Size of char is guaranteed to be 1, we're not winning anything with fancy macros.
I think it's probably better to use WTF_ARRAY_LENGTH so that we don't have to fix the code when we change the string type in the future for example (e.g. L"text").
Alexey Proskuryakov
Comment 24
2012-03-15 22:55:35 PDT
I'm quite confident that this is a wrong way to look at this. Using more complicated and uglier code today just in case that's needed for a future refactoring we don't even expect to ever happen is solving the wrong problem.
Kentaro Hara
Comment 25
2012-03-15 23:17:59 PDT
Comment on
attachment 132172
[details]
Patch (In reply to
comment #24
)
> I'm quite confident that this is a wrong way to look at this. Using more complicated and uglier code today just in case that's needed for a future refactoring we don't even expect to ever happen is solving the wrong problem.
OK, then I'll use sizeof (I do not have a strong opinion for this). I think both opinions make sense. You are right, and rniwa and tony are also right.
Kentaro Hara
Comment 26
2012-03-15 23:23:11 PDT
Created
attachment 132209
[details]
patch for landing
WebKit Review Bot
Comment 27
2012-03-16 05:32:14 PDT
Comment on
attachment 132209
[details]
patch for landing Clearing flags on attachment: 132209 Committed
r110992
: <
http://trac.webkit.org/changeset/110992
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug