Commit 2f6be682 authored by oleksandr.chekhovskyi's avatar oleksandr.chekhovskyi Committed by Commit bot

Parser: Report use counts once per feature

Reporting use counts by invoking a callback once per occurrence has
a large overhead cost in certain situations, for example when it needs
to be dispatched to a different thread (which is the case for Web Workers).

Parsing large scripts can produce a lot of occurrences (strict/sloppy mode
once per function).

Chromium (the only known user of UseCounters so far) does not actually care
about number of occurrences, but simply whether they happened at least once.
This commit changes behavior to report features at most once, which dramatically
improves performance for impacted use cases, and should not affect the only
known real world usage.

R=littledan@chromium.org
BUG=chromium:614775

Review-Url: https://codereview.chromium.org/2062203002
Cr-Commit-Position: refs/heads/master@{#36979}
parent 2d1f977c
...@@ -92,6 +92,7 @@ Mike Pennisi <mike@mikepennisi.com> ...@@ -92,6 +92,7 @@ Mike Pennisi <mike@mikepennisi.com>
Milton Chiang <milton.chiang@mediatek.com> Milton Chiang <milton.chiang@mediatek.com>
Myeong-bo Shim <m0609.shim@samsung.com> Myeong-bo Shim <m0609.shim@samsung.com>
Nicolas Antonius Ernst Leopold Maria Kaiser <nikai@nikai.net> Nicolas Antonius Ernst Leopold Maria Kaiser <nikai@nikai.net>
Oleksandr Chekhovskyi <oleksandr.chekhovskyi@gmail.com>
Paolo Giarrusso <p.giarrusso@gmail.com> Paolo Giarrusso <p.giarrusso@gmail.com>
Patrick Gansterer <paroga@paroga.com> Patrick Gansterer <paroga@paroga.com>
Peter Varga <pvarga@inf.u-szeged.hu> Peter Varga <pvarga@inf.u-szeged.hu>
......
...@@ -5214,7 +5214,7 @@ void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) { ...@@ -5214,7 +5214,7 @@ void Parser::Internalize(Isolate* isolate, Handle<Script> script, bool error) {
// Move statistics to Isolate. // Move statistics to Isolate.
for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
++feature) { ++feature) {
for (int i = 0; i < use_counts_[feature]; ++i) { if (use_counts_[feature] > 0) {
isolate->CountUsage(v8::Isolate::UseCounterFeature(feature)); isolate->CountUsage(v8::Isolate::UseCounterFeature(feature));
} }
} }
......
...@@ -3569,10 +3569,8 @@ TEST(UseAsmUseCount) { ...@@ -3569,10 +3569,8 @@ TEST(UseAsmUseCount) {
CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
CompileRun("\"use asm\";\n" CompileRun("\"use asm\";\n"
"var foo = 1;\n" "var foo = 1;\n"
"\"use asm\";\n" // Only the first one counts.
"function bar() { \"use asm\"; var baz = 1; }"); "function bar() { \"use asm\"; var baz = 1; }");
// Optimizing will double-count because the source is parsed twice. CHECK_LT(0, use_counts[v8::Isolate::kUseAsm]);
CHECK_EQ(i::FLAG_always_opt ? 4 : 2, use_counts[v8::Isolate::kUseAsm]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment