Bug 156593 - AffectsNextSibling style relation marking is inefficient
Summary: AffectsNextSibling style relation marking is inefficient
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-04-14 13:42 PDT by Antti Koivisto
Modified: 2016-04-15 00:56 PDT (History)
3 users (show)

See Also:


Attachments
patch (9.02 KB, patch)
2016-04-14 13:52 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff
patch (10.09 KB, patch)
2016-04-14 14:12 PDT, Antti Koivisto
benjamin: review+
Details | Formatted Diff | Diff
patch (9.84 KB, patch)
2016-04-15 00:07 PDT, Antti Koivisto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2016-04-14 13:42:40 PDT
We add a StyleRelation entry for each sibling to mark. With long sibling lists this can be inefficient in terms of both memory and speed. Instead make a single entry that includes the sibling count to mark.
Comment 1 Antti Koivisto 2016-04-14 13:52:47 PDT
Created attachment 276420 [details]
patch
Comment 2 Antti Koivisto 2016-04-14 14:12:25 PDT
Created attachment 276426 [details]
patch
Comment 3 Radar WebKit Bug Importer 2016-04-14 14:38:10 PDT
<rdar://problem/25735554>
Comment 4 Benjamin Poulain 2016-04-14 14:46:45 PDT
Comment on attachment 276426 [details]
patch

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

> Source/WebCore/css/SelectorChecker.cpp:94
> +        if (last.type == Style::Relation::AffectsNextSibling && last.element->previousElementSibling() == &element) {

It would likely be better to do:
    element ->nextElementSibling() == last.element
to avoid touching the memory of last.element again.

> Source/WebCore/cssjit/SelectorCompiler.cpp:2214
> +        LocalRegister lastRelation(m_registerAllocator);
> +        m_assembler.load32(sizeAddress, lastRelation);

It would be better to have this load above the mergeFailure above.

Currently the CPU will have to do two loads:
1) m_assembler.branchTest32(Assembler::Zero, sizeAddress)
2) m_assembler.load32(sizeAddress, lastRelation);

If you write:
LocalRegister size(m_registerAllocator);
m_assembler.load32(sizeAddress, size);
mergeFailure.append(m_assembler.branchTest32(Assembler::Zero, size));
m_assembler.sub32(Assembler::TrustedImm32(1), size);
...

Then you only need one load.

> Source/WebCore/cssjit/SelectorCompiler.cpp:2237
> +        m_assembler.load32(valueAddress, value);
> +        m_assembler.add32(Assembler::TrustedImm32(1), value);
> +        m_assembler.store32(value, valueAddress);

If you want you can do 
    m_assembler.add32(Assembler::TrustedImm32(1), valueAddress);

That's one instruction on x86. On ARM it generates the same code as you wrote.
Comment 5 Antti Koivisto 2016-04-15 00:07:15 PDT
Created attachment 276464 [details]
patch
Comment 6 Antti Koivisto 2016-04-15 00:42:15 PDT
> It would likely be better to do:
>     element ->nextElementSibling() == last.element
> to avoid touching the memory of last.element again.

Good idea. Did this also on the compiler path.
Comment 7 Antti Koivisto 2016-04-15 00:56:09 PDT
http://trac.webkit.org/changeset/199583