Bug 104406

Summary: JSC should scale the optimization threshold for a code block according to the cost of compiling it
Product: WebKit Reporter: Filip Pizlo <fpizlo>
Component: JavaScriptCoreAssignee: Filip Pizlo <fpizlo>
Status: RESOLVED FIXED    
Severity: Normal CC: barraclough, ggaren, gyuyoung.kim, mark.lam, mhahnenberg, msaboff, oliver, rakuco, sam, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
the patch
ggaren: review+, buildbot: commit-queue-
work in progress
fpizlo: review-
the patch
none
the patch oliver: review+

Description Filip Pizlo 2012-12-07 14:57:55 PST
Patch forthcoming.
Comment 1 Filip Pizlo 2012-12-07 15:01:01 PST
Created attachment 178289 [details]
the patch
Comment 2 WebKit Review Bot 2012-12-07 15:06:43 PST
Attachment 178289 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/ChangeLog', u'Source..." exit_code: 1
Source/JavaScriptCore/dfg/DFGCapabilities.h:42:  The parameter name "codeBlock" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/JavaScriptCore/dfg/DFGCapabilities.h:43:  The parameter name "codeBlock" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/JavaScriptCore/dfg/DFGCapabilities.h:44:  The parameter name "codeBlock" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/JavaScriptCore/dfg/DFGCapabilities.h:45:  The parameter name "codeBlock" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/JavaScriptCore/dfg/DFGCapabilities.h:46:  The parameter name "codeBlock" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/JavaScriptCore/dfg/DFGCapabilities.h:47:  The parameter name "codeBlock" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 6 in 10 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Build Bot 2012-12-07 15:33:25 PST
Comment on attachment 178289 [details]
the patch

Attachment 178289 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/15173983
Comment 4 Geoffrey Garen 2012-12-07 15:57:20 PST
Windows export file needs some babysitting:


6>CodeBlock.obj : error LNK2019: unresolved external symbol "public: int __thiscall JSC::CodeBlock::counterValueForOptimizeAfterWarmUp(void)" (?counterValueForOptimizeAfterWarmUp@CodeBlock@JSC@@QAEHXZ) referenced in function "public: void __thiscall JSC::CodeBlock::optimizeAfterWarmUp(void)" (?optimizeAfterWarmUp@CodeBlock@JSC@@QAEXXZ)
Comment 5 Geoffrey Garen 2012-12-07 16:01:19 PST
Comment on attachment 178289 [details]
the patch

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

r=me, please fix comments before landing.

> Source/JavaScriptCore/dfg/DFGCapabilities.h:48
> +bool mightCompileEval(CodeBlock* codeBlock);
> +bool mightCompileProgram(CodeBlock* codeBlock);
> +bool mightCompileFunctionForCall(CodeBlock* codeBlock);
> +bool mightCompileFunctionForConstruct(CodeBlock* codeBlock);
> +bool mightInlineFunctionForCall(CodeBlock* codeBlock);
> +bool mightInlineFunctionForConstruct(CodeBlock* codeBlock);
>  

Style bot is right here, for once.
Comment 6 Filip Pizlo 2012-12-07 16:23:05 PST
(In reply to comment #4)
> Windows export file needs some babysitting:
> 
> 
> 6>CodeBlock.obj : error LNK2019: unresolved external symbol "public: int __thiscall JSC::CodeBlock::counterValueForOptimizeAfterWarmUp(void)" (?counterValueForOptimizeAfterWarmUp@CodeBlock@JSC@@QAEHXZ) referenced in function "public: void __thiscall JSC::CodeBlock::optimizeAfterWarmUp(void)" (?optimizeAfterWarmUp@CodeBlock@JSC@@QAEXXZ)

I think it's once again misuse of #ifdef's like ENABLE(DFG.. and so on. :-/  I'm trying to fiddle with it now.
Comment 7 Filip Pizlo 2012-12-07 16:23:13 PST
(In reply to comment #5)
> (From update of attachment 178289 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=178289&action=review
> 
> r=me, please fix comments before landing.
> 
> > Source/JavaScriptCore/dfg/DFGCapabilities.h:48
> > +bool mightCompileEval(CodeBlock* codeBlock);
> > +bool mightCompileProgram(CodeBlock* codeBlock);
> > +bool mightCompileFunctionForCall(CodeBlock* codeBlock);
> > +bool mightCompileFunctionForConstruct(CodeBlock* codeBlock);
> > +bool mightInlineFunctionForCall(CodeBlock* codeBlock);
> > +bool mightInlineFunctionForConstruct(CodeBlock* codeBlock);
> >  
> 
> Style bot is right here, for once.

Yup, I fixed.
Comment 8 Filip Pizlo 2012-12-07 16:44:02 PST
Created attachment 178303 [details]
work in progress

This should make EWS happy.
Comment 9 Filip Pizlo 2012-12-08 16:49:54 PST
Comment on attachment 178303 [details]
work in progress

This causes a massive regression on Kraken audio benchmarks.  The regression only shows up in browser.  Investigating the reasons now.
Comment 10 Filip Pizlo 2012-12-08 21:53:59 PST
It looks like what is going on is that we've got some code blocks in the Kraken audio benchmarks that rely heavily on OSR exit profiling.  Our previous threshold for triggering recompilation was 5000 (thresholdForOptimizeAfterLongWarmUp); this code effectively increases that threshold since we have scaling by instruction count and most code blocks that benefit from recompilation tend to be large-ish.  

So, I experimented with lowering the thresholdForOptimizeAfterLongWarmUp.  With 3000, we already neutralize the slow-down on Kraken.  But lowering it further seems to help even more.  It looks like setting it to 1000 helps the most.  Here are the performance numbers on various benchmarks for 1000, 2000, and 3000:


3000:
jsc:
   0.7% faster on SunSpider
   neutral on V8v7
   ~1% slower on Kraken
drt:
   1% faster on SunSpider
   ~1% faster on V8v7
   neutral on Octane
   2% slower on Kraken
   ~10% faster on JSBench
   1.5% faster on DSP

2000:
jsc:
   0.9% faster on SunSpider
   neutral on V8v7
   0.9% slower on Kraken
drt:
   neutral on SunSpider
   0.6% faster on V8v7
   ~2% slower on Kraken
   ~7.8% faster on JSBench
   1.9% faster on DSP

1000:
jsc:
   1.4% faster on SunSpider
   0.4% slower on V8v7
   0.6% slower on Kraken
drt:
   0.6% faster on SunSpider
   1.3% faster on V8v7
   neutral on Kraken
   1% faster on JSBench
   neutral on DSP

Further tests seem to imply that the speed-up on SunSpider in DRT is closer to 1% with 1000, but I can't be sure.  Anyway, 1000 seems best since I'd rather be neutral on Kraken and get a 1% V8v7 & SunSpider speed-up.
Comment 11 Filip Pizlo 2012-12-08 23:00:53 PST
Created attachment 178396 [details]
the patch

I fixed all regressions.  It took some effort.
Comment 12 WebKit Review Bot 2012-12-08 23:04:09 PST
Attachment 178396 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/CMakeLists.txt', u'S..." exit_code: 1
Source/JavaScriptCore/bytecode/CodeBlock.cpp:3110:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Source/JavaScriptCore/bytecode/CodeBlock.cpp:3115:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Source/JavaScriptCore/bytecode/CodeBlock.cpp:3125:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Total errors found: 3 in 20 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Filip Pizlo 2012-12-08 23:05:34 PST
Created attachment 178397 [details]
the patch

fix style
Comment 14 Oliver Hunt 2012-12-09 12:16:49 PST
Comment on attachment 178397 [details]
the patch

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

r=me

> Source/JavaScriptCore/profiler/ProfilerDatabase.cpp:61
> +    Bytecodes* result = addBytecodes(
> +        codeBlock->hash(), codeBlock->sourceCodeForTools());

something this short could just be a single line :p
Comment 15 Filip Pizlo 2012-12-09 12:30:27 PST
(In reply to comment #14)
> (From update of attachment 178397 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=178397&action=review
> 
> r=me
> 
> > Source/JavaScriptCore/profiler/ProfilerDatabase.cpp:61
> > +    Bytecodes* result = addBytecodes(
> > +        codeBlock->hash(), codeBlock->sourceCodeForTools());
> 
> something this short could just be a single line :p

You make a fair point!  Fixed.
Comment 16 Filip Pizlo 2012-12-09 12:43:13 PST
Landed in http://trac.webkit.org/changeset/137094
Comment 17 Geoffrey Garen 2012-12-10 13:49:31 PST
Should we reconsider these limits, now that bug 104500 has been discovered and fixed?