Bug 81449 - [Performance] Optimize sequentially accessed childNodes[]
Summary: [Performance] Optimize sequentially accessed childNodes[]
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-17 08:32 PDT by Kentaro Hara
Modified: 2022-08-02 09:15 PDT (History)
9 users (show)

See Also:


Attachments
Performance test (1.63 KB, text/html)
2012-03-17 08:33 PDT, Kentaro Hara
no flags Details
Patch (3.81 KB, patch)
2012-03-17 08:36 PDT, Kentaro Hara
no flags Details | Formatted Diff | Diff
Patch (4.00 KB, patch)
2012-03-18 04:37 PDT, Kentaro Hara
buildbot: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kentaro Hara 2012-03-17 08:32:48 PDT
In most cases childNodes[] are accessed sequentially. We can optimize the fast path for sequential accesses.
Comment 1 Kentaro Hara 2012-03-17 08:33:54 PDT
Created attachment 132460 [details]
Performance test
Comment 2 Kentaro Hara 2012-03-17 08:36:48 PDT
Created attachment 132461 [details]
Patch
Comment 3 Build Bot 2012-03-17 08:57:15 PDT
Comment on attachment 132461 [details]
Patch

Attachment 132461 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/11964894
Comment 4 WebKit Review Bot 2012-03-17 09:31:38 PDT
Comment on attachment 132461 [details]
Patch

Attachment 132461 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/11966841

New failing tests:
jquery/core.html
jquery/manipulation.html
jquery/traversing.html
Comment 5 Erik Arvidsson 2012-03-17 11:06:55 PDT
This has some issues. You need to ensure that you don't cache null items.
Comment 6 Kentaro Hara 2012-03-18 04:37:11 PDT
Created attachment 132489 [details]
Patch
Comment 7 Kentaro Hara 2012-03-18 04:37:38 PDT
(In reply to comment #5)
> This has some issues. You need to ensure that you don't cache null items.

Good point. Fixed. Thanks.
Comment 8 Alexey Proskuryakov 2012-03-18 20:22:15 PDT
Comment on attachment 132489 [details]
Patch

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

> In most cases childNodes[] are accessed sequentially. We can optimize the fast path for sequential accesses.

Please provide evidence for this claim.

> Source/WebCore/dom/ChildNodeList.h:46
> +        virtual Node* item(unsigned index) const OVERRIDE
> +        {
> +            // fast path

What's the benefit of putting this function implementation into header? Is it ever called directly to be inlined?

> Source/WebCore/dom/ChildNodeList.h:71
> +        virtual Node* itemSlow(unsigned index) const OVERRIDE;

Why is this function virtual, and what does it override? Do you really need to split this into two functions?
Comment 9 Erik Arvidsson 2012-03-19 09:53:58 PDT
Comment on attachment 132489 [details]
Patch

I feel like this one could be restructured to be a lot clearer. Both item and itemSlow try to be fast. In both cases we only have to do previousSibling once if index === lastItemOffset - 1.

The difference is that we are doing a lot of extra work in the common cases of lastItemOffset+1 and lastItemOffset-1. By restructuring the code I think we could make this cleaner and still get a performance boost for the common cases.
Comment 10 Build Bot 2012-03-19 11:10:50 PDT
Comment on attachment 132489 [details]
Patch

Attachment 132489 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/11985488
Comment 11 Kentaro Hara 2012-03-21 03:51:52 PDT
Comment on attachment 132489 [details]
Patch

Thanks for comments. I'll update the patch tomorrow.
Comment 12 Ahmad Saleem 2022-08-02 04:07:23 PDT
*** Safari 15.6 on macOS 12.5 ***

sequential childNodes : 312.8ms 
reverse sequential childNodes : 304.4ms 

*** Chrome Canary 106 ***

sequential childNodes : 1156.8ms
reverse sequential childNodes : 1171ms

*** Firefox Nightly 105 ***


sequential childNodes : 856.6ms
reverse sequential childNodes : 867.2ms

________

Safari is the fastest in the attached test case, I don't think this patch landed, can we work on it (via rebase) or mark it as "RESOLVED LATER"? Thanks!
Comment 13 Ryosuke Niwa 2022-08-02 09:15:33 PDT
This is won't fix at this point.