New issue
Advanced search Search tips

Issue 606695 link

Starred by 6 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Task



Sign in to add a comment

Unify string -> id parsing (e.g. property names, pseudo-selector names, etc.) in Blink

Project Member Reported by timloh@chromium.org, Apr 26 2016

Issue description

We currently have too many different ways to parse strings to ids in Blink.

string->enum:
- CSSValueKeyword, ~800 values, uses gperf (CSSValueKeywords.in, make_css_value_keywords.py)
- CSSPropertyID, ~500 values, uses gperf (CSSProperties.in, make_css_property_names.py)
- CSSPrimitiveValue::UnitType, 28 values, HashMap lookup
- CSSSelector::PseudoType, ~80 values, binary search over (string, enum) pairs

string->StringImpl*:
- lookupHTMLTag, ~500 values, uses a generated switch-statement trie (make_element_lookup_trie.py), input is already lower-case

These all pretty much do the same thing, just with different values, so it would be nice if these could all be handled the same way. We want to avoid String allocations, which we currently do when parsing primitive unit types.

We also have make_token_matcher.py, which preprocesses a .cpp file looking for SWITCH and CASE tags. It's only used by HTMLMetaElement-in.cpp currently and with only a few cases each. I don't think this preprocessing is worthwhile if it is only used in a few small switch statements and we should consider removing this.
 

Comment 1 by meade@chromium.org, May 10 2016

Cc: -meade@chromium.org
Owner: meade@chromium.org
Project Member

Comment 2 by bugdroid1@chromium.org, May 13 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/28c11f51b7b91165ea4c108afceb1ac30e066c35

commit 28c11f51b7b91165ea4c108afceb1ac30e066c35
Author: meade <meade@chromium.org>
Date: Fri May 13 08:39:57 2016

Factor and simplify generation of the lookup trie used for HTMLLookupTrie.

This is in preparation for making more classes use the lookup trie.

Difference before and after for HTMLElementLookupTrie.cpp is here:
https://www.diffchecker.com/lqhiueko

BUG=606695

Review-Url: https://codereview.chromium.org/1978703002
Cr-Commit-Position: refs/heads/master@{#393478}

[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/build/scripts/make_element_lookup_trie.py
[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/build/scripts/scripts.gni
[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/build/scripts/scripts.gypi
[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/build/scripts/templates/ElementLookupTrie.cpp.tmpl
[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/build/scripts/templates/macros.tmpl
[add] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/build/scripts/trie_builder.py
[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/core/BUILD.gn
[modify] https://crrev.com/28c11f51b7b91165ea4c108afceb1ac30e066c35/third_party/WebKit/Source/core/core_generated.gyp

Comment 3 by timloh@chromium.org, May 24 2016

FWIW I tested using the trie generator on CSS property names and it's noticeably faster but increases binary size by ~200KB (for the unit type trie the binary size change is small).
Project Member

Comment 4 by bugdroid1@chromium.org, May 25 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/a753d727f2d92f67b594312a6710c931b37a49b3

commit a753d727f2d92f67b594312a6710c931b37a49b3
Author: timloh <timloh@chromium.org>
Date: Wed May 25 10:02:34 2016

Avoid string allocation when parsing CSSPrimitiveValue::UnitType

Currently the CSSPrimitiveValue::fromName function, which parses strings
to unit types, takes a String argument. This means that the CSS parser
needs to allocate a String (since it would only otherwise have a
CSSParserString). This patch avoids this allocation using a generated
switch-statement trie instead.

Generated file: http://paste.ubuntu.com/16652358/

This improves performance of the inline-transform-benchmark test from
https://bugs.chromium.org/p/chromium/issues/detail?id=605792, reducing
the time spent in CSSParserImpl::parseValue by 10%.

Patch originally written by meade@chromium.org:
https://codereview.chromium.org/1938343002

BUG=605792,606695

Review-Url: https://codereview.chromium.org/2002383002
Cr-Commit-Position: refs/heads/master@{#395849}

[add] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/build/scripts/make_css_primitive_value_unit_trie.py
[add] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/build/scripts/templates/CSSPrimitiveValueUnitTrie.cpp.tmpl
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/BUILD.gn
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/CoreInitializer.cpp
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/core.gypi
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/core_generated.gyp
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/core_generated.gypi
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp
[add] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/css/CSSPrimitiveValueUnitTrie.h
[add] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/css/CSSPrimitiveValueUnits.in
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/css/cssom/CSSAngleValue.cpp
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/css/cssom/CSSLengthValue.cpp
[modify] https://crrev.com/a753d727f2d92f67b594312a6710c931b37a49b3/third_party/WebKit/Source/core/css/parser/CSSParserToken.cpp

Project Member

Comment 5 by bugdroid1@chromium.org, Jun 3 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/e22ff8c96ff8b3fa85e1f51b98daf27d5e68a09d

commit e22ff8c96ff8b3fa85e1f51b98daf27d5e68a09d
Author: meade <meade@chromium.org>
Date: Fri Jun 03 12:01:40 2016

Delete remaining unused function definitionss from CSSPrimitiveValue header

These functions were removed from the cpp file in
https://codereview.chromium.org/2002383002.

BUG=605792,606695

Review-Url: https://codereview.chromium.org/2036923002
Cr-Commit-Position: refs/heads/master@{#397686}

[modify] https://crrev.com/e22ff8c96ff8b3fa85e1f51b98daf27d5e68a09d/third_party/WebKit/Source/core/css/CSSPrimitiveValue.h

Comment 6 by meade@chromium.org, Sep 21 2016

Cc: meade@chromium.org
Labels: Hotlist-GoodFirstBug
Owner: ----
I don't have time to work on this right now, so here's the status of this bug: Tim and I updated CSSPrimitiveValue::UnitType to use a trie thing. We decided not to change the ones using gperf as it regressed the binary size too much, which leaves updating CSSSelector::PseudoType for someone with some free time :)

- CSSValueKeyword, ~800 values, uses gperf (CSSValueKeywords.in, make_css_value_keywords.py)
- CSSPropertyID, ~500 values, uses gperf (CSSProperties.in, make_css_property_names.py)
-> CSSPrimitiveValue::UnitType, uses generated switch-statement trie (make_element_lookup_trie.py)
- CSSSelector::PseudoType, ~80 values, binary search over (string, enum) pairs
- lookupHTMLTag, ~500 values, uses a generated switch-statement trie (make_element_lookup_trie.py), input is already lower-case

Comment 7 by nainar@chromium.org, Feb 13 2017

Labels: Update-Quarterly

Comment 8 by h...@chromium.org, Jul 19 2017

I'm interested in this.

The switch-statement trie doesn't look optimal since it uses indirect branches and large jump tables.

I wonder if it would be possible to come up with either a perfect hash solution that's fast and simple, or if one could generate table-driven tries that are faster and smaller.

Comment 9 by meade@chromium.org, Jul 20 2017

We still use gperf in CSSValueKeyword and CSSPropertyID, is this the kind of thing you were thinking? 
e.g. https://cs.chromium.org/chromium/src/out/Debug/gen/blink/core/CSSValueKeywords.cpp?
Labels: Code-Parser

Comment 11 by shend@chromium.org, Oct 31 2017

Labels: ApproachableBug
Labels: -Update-Quarterly
Project Member

Comment 13 by sheriffbot@chromium.org, Dec 6

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Cc: -meade@chromium.org -esprehn@chromium.org
Labels: -Type-Feature Type-Task
Status: Available (was: Untriaged)

Sign in to add a comment