HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

goog.isDef does not inline in ADVANCED_OPTIMIZATION while goog.isDefAndNotNull does #1279

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. use goog.isDef(someVar) many times:
if (goog.isDef(someVar)) ...
2. compile in ADVANCED_OPTIMIZATIONS
3. goog.isDef are still calls: if (a(b))...
4. using goog.isDefAndNotNull always inlines

What is the expected output? What do you see instead?
if (void 0!==b)...

What version of the product are you using? On what operating system?
Windows, v20140303

Please provide any additional information below.

Original issue reported on code.google.com by alexey.l...@gmail.com on 12 Mar 2014 at 11:39

GoogleCodeExporter commented 9 years ago
Whether a function gets inlined depends on whether inlining it will save space:

"f(a)" is smaller than "a != void 0", and will generally only be inlined if the 
definition can be removed and there are a sufficiently small number of uses 
that the function definition doesn't out way the size of the calls.

If you would like something changed here you will have to provide some 
additional justification.

Original comment by concavel...@gmail.com on 13 Mar 2014 at 12:16

GoogleCodeExporter commented 9 years ago
Well, but "f(a)" also smaller than "a != null", but goog.isDefAndNotNull does 
inline.
Am I missed something?
I am very using goog.isDef() and want to prevent performance penalty (due to 
function call) and I hoped compiler does it.

Original comment by alexey.l...@gmail.com on 13 Mar 2014 at 4:58

GoogleCodeExporter commented 9 years ago
I don't know much about the inlining heuristics of Closure compiler, but you 
shouldn't worry about the performance penalty. Simple function calls like that 
are definitely inlined by the JavaScript VMs.

Original comment by dim...@google.com on 13 Mar 2014 at 7:37

GoogleCodeExporter commented 9 years ago
May be, in theory. But jsperf tests show performance degradation:
http://jsperf.com/function-calls-vs-spagetti
It does matter for our app, 'cos it very large and full of calls of small 
methods (especially after adopting code to closure compiler).

Original comment by alexey.l...@gmail.com on 13 Mar 2014 at 8:02