Bug 16585

Summary: Optimize variable declarations
Product: WebKit Reporter: Maciej Stachowiak <mjs>
Component: JavaScriptCoreAssignee: Maciej Stachowiak <mjs>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P3    
Version: 528+ (Nightly build)   
Hardware: All   
OS: OS X 10.4   
Attachments:
Description Flags
optimize var statements - 3.7% speedup
none
cleaned up version (now measures as 3.5% speedup) eric: review+

Description Maciej Stachowiak 2007-12-23 07:51:49 PST
Variable declaration statements can be replaced at parse time with assignments if there are initializers, or nothing at all if there aren't. The actual declaration logic is handled on entering the function body anyway.
Comment 1 Maciej Stachowiak 2007-12-23 07:55:24 PST
Created attachment 18071 [details]
optimize var statements - 3.7% speedup
Comment 2 Eric Seidel (no email) 2007-12-23 15:58:46 PST
Comment on attachment 18071 [details]
optimize var statements - 3.7% speedup

So my comments deal entirely with code readability.  AFAICT, the functionality looks fine:

ExprStatementNode<false> and ExprStatementNode<true> should have nicely named typdefs.  Probably ExprStatementNode should also change names to some sort of ExprStatementNodeBase or the like.

As part of that <isVar> needs a more descriptive name.  Small functions would be better done using the typdef classes, larger functions can be defined using ExprStatementNode<betterNameThanIsVar>::

If you look at the formatted diff, it appears you added a whole bunch of extra whitespace.

I think passing int attrs as part of appendToVarDeclarationList and using DeclarationStacks::IsConstant and DeclarationStacks::HasInitializerat the callsites would be clearer.  At least at the callsites. :)

 1807       ForNode(ExpressionNode* e1, ExpressionNode* e2, ExpressionNode* e3, StatementNode* s, bool e1WasVarDecl) KJS_FAST_CALL

I was trying to come up with a cleaner way of expressing the same.  Using an enum "FirstExprIsVarDecl" instead of a bool would lead to cleaner callsites... I guess that's about the best I can come up with for right now.

If you fix at least some of those readability issues, this is totally fine for landing.  Congrats on such an awesome speedup.
Comment 3 Maciej Stachowiak 2007-12-24 01:14:05 PST
Created attachment 18090 [details]
cleaned up version (now measures as 3.5% speedup)
Comment 4 Eric Seidel (no email) 2007-12-24 01:44:33 PST
Comment on attachment 18090 [details]
cleaned up version (now measures as 3.5% speedup)

Looks good to me.