Bug 107150 - BackgroundHTMLParser shouldn't create AtomicStrings
Summary: BackgroundHTMLParser shouldn't create AtomicStrings
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adam Barth
URL:
Keywords:
Depends on:
Blocks: 106127
  Show dependency treegraph
 
Reported: 2013-01-17 11:52 PST by Adam Barth
Modified: 2013-01-18 15:16 PST (History)
4 users (show)

See Also:


Attachments
Patch (8.92 KB, patch)
2013-01-17 11:56 PST, Adam Barth
no flags Details | Formatted Diff | Diff
Patch (8.99 KB, patch)
2013-01-17 12:04 PST, Adam Barth
no flags Details | Formatted Diff | Diff
rebase to TOT (9.13 KB, patch)
2013-01-17 17:26 PST, Adam Barth
no flags Details | Formatted Diff | Diff
works---not for review (5.80 KB, patch)
2013-01-17 18:49 PST, Adam Barth
no flags Details | Formatted Diff | Diff
Patch (7.54 KB, patch)
2013-01-18 12:36 PST, Adam Barth
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Barth 2013-01-17 11:52:59 PST
BackgroundHTMLParser shouldn't make an extra copy of every tag name
Comment 1 Adam Barth 2013-01-17 11:56:42 PST
Created attachment 183236 [details]
Patch
Comment 2 Eric Seidel (no email) 2013-01-17 11:59:29 PST
Comment on attachment 183236 [details]
Patch

Do we know if this is faster?  And do we have any good way to catch that w'ere not using regular equal with these tags?  HTMLNames is really dangerous to have on this background thread.  (Also this code is still wrong wrt namespaces, but that's a separate bug.)
Comment 3 Adam Barth 2013-01-17 11:59:32 PST
Comment on attachment 183236 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        Previously, we were creating an AtomicString from the HTMLToken for
> +        every start and end tag. This caused us to allocate a new StringImpl
> +        and memcpy the start and end tag names an extra time.

I guess this isn't quite true since AtomicString will atomize them.
Comment 4 Adam Barth 2013-01-17 12:02:30 PST
> Do we know if this is faster?

Tony is still upstreaming your work from last night, so I haven't been able to run the performance test.

In general, though, I don't think we should be creating AtomicStrings on the background thread.  That creates a static dependency, which will block integration with libdispatch later.

> And do we have any good way to catch that w'ere not using regular equal with these tags?

Nope.  We need to be careful with how we're using HTMLNames.

> Also this code is still wrong wrt namespaces, but that's a separate bug.

Yes, this patch does not attempt to address that bug.
Comment 5 Adam Barth 2013-01-17 12:04:39 PST
Created attachment 183239 [details]
Patch
Comment 6 Adam Barth 2013-01-17 12:05:14 PST
I've adjusted the ChangeLog to motivate the change without referencing performance.
Comment 7 Eric Seidel (no email) 2013-01-17 12:08:09 PST
Comment on attachment 183239 [details]
Patch

I'm still concerned about using HTMLNames w/o any ASSERT protections. :)  And I would still like to know what the perf impact is.  run-perf-tests parser/html-parser-srcdoc.html should show a difference.  :)  I guess we should just rename that to -threaded, and have it force on the threaded parser.
Comment 8 Adam Barth 2013-01-17 12:09:11 PST
We can wait on this patch until we finish upstreaming the branch if you like.
Comment 9 Adam Barth 2013-01-17 17:26:32 PST
Created attachment 183325 [details]
rebase to TOT
Comment 10 Adam Barth 2013-01-17 18:49:26 PST
Created attachment 183348 [details]
works---not for review
Comment 11 Adam Barth 2013-01-17 18:56:09 PST
I need to study it more carefully, but this patch does not appear to have a performance impact on the srcdoc benchmark.
Comment 12 Eric Seidel (no email) 2013-01-17 18:59:44 PST
Our benchmark probably needs improvement (we still don't really keep the main thread very busy).  But I suspect that this stuff is also rather subtle, and as you say, just need more study.
Comment 13 Adam Barth 2013-01-18 12:18:35 PST
This looks like it saves around ~10% of the time on the parser thread.  I'm going to clean it up for review.
Comment 14 Adam Barth 2013-01-18 12:26:25 PST
Running the parser-srcdoc benchmark with the patch in bug 107236 applied:

== With patch ==

Running Time    Self        Symbol Name
12129.0ms   76.4%   0.0     Main Thread  0x878fe
3628.0ms   22.8%    0.0     WebCore::HTMLParserThread::runLoop  0x8792f

== Without patch ==

Running Time    Self        Symbol Name
11846.0ms   73.9%   0.0     Main Thread  0x87b04
4100.0ms   25.5%    0.0     WebCore::HTMLParserThread::runLoop  0x87b28

That's a 2.3% savings on the main thread and an 11.5% savings on the background thread.
Comment 15 Adam Barth 2013-01-18 12:36:39 PST
Created attachment 183526 [details]
Patch
Comment 16 Eric Seidel (no email) 2013-01-18 12:49:30 PST
I assume that you also saw a total reduction in time when instruments was not running? :)
Comment 17 Adam Barth 2013-01-18 14:00:08 PST
(In reply to comment #16)
> I assume that you also saw a total reduction in time when instruments was not running? :)

== With patch ==

avg 464.88400000016554 ms
median 431.9385000017064 ms
stdev 131.61021047785155 ms

== Without patch ==

avg 477.63914999995905 ms
median 443.0915000011737 ms
stdev 138.40526205197622 ms

Result: 2.6% faster
Comment 18 WebKit Review Bot 2013-01-18 15:16:44 PST
Comment on attachment 183526 [details]
Patch

Clearing flags on attachment: 183526

Committed r140212: <http://trac.webkit.org/changeset/140212>
Comment 19 WebKit Review Bot 2013-01-18 15:16:48 PST
All reviewed patches have been landed.  Closing bug.