Bug 126199 - Use the Selector Code Generator for resolving style
Summary: Use the Selector Code Generator for resolving style
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: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-23 19:02 PST by Benjamin Poulain
Modified: 2014-01-13 16:23 PST (History)
12 users (show)

See Also:


Attachments
Patch (4.38 KB, patch)
2013-12-23 19:03 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (4.90 KB, patch)
2014-01-12 17:29 PST, Benjamin Poulain
no flags Details | Formatted Diff | Diff
Patch (4.74 KB, patch)
2014-01-12 22:04 PST, Benjamin Poulain
rniwa: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2013-12-23 19:02:32 PST
Use the Selector Code Generator for resolving style
Comment 1 Benjamin Poulain 2013-12-23 19:03:03 PST
Created attachment 219952 [details]
Patch
Comment 2 EFL EWS Bot 2013-12-23 19:07:19 PST
Comment on attachment 219952 [details]
Patch

Attachment 219952 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/50458029
Comment 3 EFL EWS Bot 2013-12-23 20:48:18 PST
Comment on attachment 219952 [details]
Patch

Attachment 219952 [details] did not pass efl-wk2-ews (efl-wk2):
Output: http://webkit-queues.appspot.com/results/45698122
Comment 4 kov's GTK+ EWS bot 2013-12-23 22:47:09 PST
Comment on attachment 219952 [details]
Patch

Attachment 219952 [details] did not pass gtk-ews (gtk):
Output: http://webkit-queues.appspot.com/results/51868073
Comment 5 Antti Koivisto 2013-12-26 12:15:25 PST
Comment on attachment 219952 [details]
Patch

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

> Source/WebCore/css/ElementRuleCollector.cpp:301
>  inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, PseudoId& dynamicPseudo)
>  {
>      const StyleResolver::State& state = m_state;
> +#if ENABLE(CSS_SELECTOR_JIT)
> +    void* compiledSelectorChecker = ruleData.compiledSelectorCodeRef.code().executableAddress();
> +    if (!compiledSelectorChecker && ruleData.compilationStatus == SelectorCompilationStatus::NotCompiled) {
> +        JSC::VM* vm = document().scriptExecutionContext()->vm();
> +        ruleData.compilationStatus = SelectorCompiler::compileSelector(ruleData.selector(), vm, ruleData.compiledSelectorCodeRef);
> +        compiledSelectorChecker = ruleData.compiledSelectorCodeRef.code().executableAddress();
> +    }

This compiles too eagerly. If you look below in ruleData.hasFastCheckableSelector() branch you see there are number of cases we resolve without calling into SelectorCheckerFastPath at all. Those cases will use more memory and may get slower by activating the JIT. We should probably not compile selectors that are in this category.

Does the infrastructure support compiling off the main thread? I think optimally we would kick off the compiling during RuleData construction and use the compiled versions when ready.

> Source/WebCore/css/ElementRuleCollector.cpp:312
> +    if (compiledSelectorChecker) {
> +        if (ruleData.compilationStatus == SelectorCompilationStatus::SimpleSelectorChecker) {
> +            if (m_pseudoStyleRequest.pseudoId != NOPSEUDO)
> +                return false;
> +            SelectorCompiler::SimpleSelectorChecker selectorChecker = SelectorCompiler::simpleSelectorCheckerFunction(compiledSelectorChecker, ruleData.compilationStatus);
> +            return selectorChecker(state.element());
> +        }
> +        ASSERT(ruleData.compilationStatus == SelectorCompilationStatus::SelectorCheckerWithCheckingContext);
> +
> +        if (m_pseudoStyleRequest.pseudoId != NOPSEUDO)
> +            return false;

NOPSEUDO tests can move before the compilationStatus check and combined.

> Source/WebCore/css/RuleSet.h:84
> +#if ENABLE(CSS_SELECTOR_JIT)
> +    mutable SelectorCompilationStatus compilationStatus;
> +    mutable JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
> +#endif // ENABLE(CSS_SELECTOR_JIT)

These fields should be optimized for memory at some point (I think we can manage with 64bits or less for all this). We can have large numbers of selectors and so RuleDatas. We also shouldn't generate code for simplest selectors that are resolved by hash look-ups and don't need overhead of even having these fields.
Comment 6 Benjamin Poulain 2014-01-12 17:29:18 PST
Created attachment 220991 [details]
Patch
Comment 7 EFL EWS Bot 2014-01-12 19:41:24 PST
Comment on attachment 220991 [details]
Patch

Attachment 220991 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/6029259655086080
Comment 8 kov's GTK+ EWS bot 2014-01-12 20:54:17 PST
Comment on attachment 220991 [details]
Patch

Attachment 220991 [details] did not pass gtk-ews (gtk):
Output: http://webkit-queues.appspot.com/results/6717223087374336
Comment 9 EFL EWS Bot 2014-01-12 21:45:20 PST
Comment on attachment 220991 [details]
Patch

Attachment 220991 [details] did not pass efl-wk2-ews (efl-wk2):
Output: http://webkit-queues.appspot.com/results/6353650481889280
Comment 10 Benjamin Poulain 2014-01-12 22:04:24 PST
Created attachment 221004 [details]
Patch
Comment 11 Ryosuke Niwa 2014-01-13 08:40:06 PST
Comment on attachment 221004 [details]
Patch

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

> Source/WebCore/css/ElementRuleCollector.cpp:312
> +        JSC::VM* vm = document().scriptExecutionContext()->vm();

We should be using a reference instead in all these places (probably should be done in a separate patch though).

> Source/WebCore/css/ElementRuleCollector.cpp:321
> +            SelectorCompiler::SimpleSelectorChecker selectorChecker = SelectorCompiler::simpleSelectorCheckerFunction(compiledSelectorChecker, ruleData.compilationStatus);

Do we really need this temporary variable?  Also, isn't this the case where auto will be useful?
Since this is a function pointer into a JIT'ed code, type doesn't give us any extra information anyway.

> Source/WebCore/css/RuleSet.h:84
> +#if ENABLE(CSS_SELECTOR_JIT)
> +    mutable SelectorCompilationStatus compilationStatus;
> +    mutable JSC::MacroAssemblerCodeRef compiledSelectorCodeRef;
> +#endif // ENABLE(CSS_SELECTOR_JIT)
> +

These should really be private and have accessors instead.
Comment 12 Benjamin Poulain 2014-01-13 16:23:46 PST
Committed r161917: <http://trac.webkit.org/changeset/161917>