Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Issue 2100573002: Avoid copying strings when parsing CSS colors on the slow path. (Closed)

Created:
4 years, 6 months ago by esprehn
Modified:
4 years, 5 months ago
CC:
ajuma+watch_chromium.org, darktears, apavlov+blink_chromium.org, blink-reviews, blink-reviews-css, blink-reviews-platform-graphics_chromium.org, Rik, chromium-reviews, danakj+watch_chromium.org, dglazkov+blink, dshwang, drott+blinkwatch_chromium.org, krit, f(malita), jbroman, Justin Novosad, pdr+graphicswatchlist_chromium.org, rwlbuis, Stephen Chennney
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Avoid copying strings when parsing CSS colors on the slow path. parseHexColor was always calling value().toString() forcing a string copy of every hex color inside the parser. We can instead change Color::parseHexColor to take a StringView and pass value() directly avoiding this string copy. CSSTokenizer::consumeName() also has a fast path which avoids making string copies when the token value doesn't contain escapes. This path didn't work when the input to the parser was a value that's not followed by a semi-colon (ex. color = "#ccc" in JS) because peekWithoutReplacement would return NUL when we accessed the first out of range position, which then aborted the loop, and made us go down the string copy path usually used for escapes. This patch makes parsing colors on the slow path 2x faster: ex. for (var i = 0; i < 50000; ++i) { span.style.color = " #ddd"; // note the space before the #. The color parsing fast path still seems about 2x faster than this optimized path, but this patch gets us much closer to not needing the color parsing fast path and makes whitespace in your colors less terrible for performance. The patch will also help CSS parsing in general by avoiding string copies for every hex color. BUG=605792 Committed: https://crrev.com/0d4987c045a9cbc5033295f0aee38a2456f039bf Cr-Commit-Position: refs/heads/master@{#402097}

Patch Set 1 #

Patch Set 2 : missing else. #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+23 lines, -15 lines) Patch
M third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp View 1 2 chunks +7 lines, -4 lines 0 comments Download
M third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp View 1 chunk +11 lines, -6 lines 1 comment Download
M third_party/WebKit/Source/core/css/parser/CSSTokenizerInputStream.h View 1 chunk +1 line, -0 lines 0 comments Download
M third_party/WebKit/Source/platform/graphics/Color.h View 2 chunks +2 lines, -1 line 0 comments Download
M third_party/WebKit/Source/platform/graphics/Color.cpp View 1 chunk +2 lines, -4 lines 0 comments Download

Messages

Total messages: 13 (6 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2100573002/20001
4 years, 6 months ago (2016-06-25 01:58:13 UTC) #3
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
4 years, 6 months ago (2016-06-25 03:20:09 UTC) #5
esprehn
4 years, 6 months ago (2016-06-25 05:55:29 UTC) #7
Timothy Loh
lgtm https://codereview.chromium.org/2100573002/diff/20001/third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp File third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp (right): https://codereview.chromium.org/2100573002/diff/20001/third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp#newcode675 third_party/WebKit/Source/core/css/parser/CSSTokenizer.cpp:675: if (cc == '\0' && m_input.offset() + size ...
4 years, 5 months ago (2016-06-27 00:14:25 UTC) #8
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2100573002/20001
4 years, 5 months ago (2016-06-27 00:59:41 UTC) #10
commit-bot: I haz the power
Committed patchset #2 (id:20001)
4 years, 5 months ago (2016-06-27 02:49:58 UTC) #11
commit-bot: I haz the power
4 years, 5 months ago (2016-06-27 02:52:24 UTC) #13
Message was sent while issue was closed.
Patchset 2 (id:??) landed as
https://crrev.com/0d4987c045a9cbc5033295f0aee38a2456f039bf
Cr-Commit-Position: refs/heads/master@{#402097}

Powered by Google App Engine
This is Rietveld 408576698