BTF Measurements

Jason Orendorff jason.orendorff at
Tue Mar 13 08:15:53 PDT 2012

Kevin Smith wrote:
> For the surveyed code,
> the percentage of function expressions which do not reference "this" ranges
> between 31% and 87%.  About half of all function expressions are suitable
> for conversion to BTFs.  Clearly BTFs would offer immediate quantifiable
> benefit.

This is good work, but I don't think every function that doesn’t use
'this' is a supporting use case for bound-this functions, though. Many
functions are like this:

    panels.each(function (p) { p.fadeIn(); });

and that function would not benefit at all from being converted to a
bound-this function.

A function is only a use case for BTF if it also *does* use the
enclosing function's 'this' somehow. That's harder to detect
statically, but even harder to find is the code that gets rewritten a
different way because of this-binding. :-\

> Of the surveyed code, about 19% of BTF candidates contain a return statement
> as their first statement.  This suggests that BTF syntax should be optimized
> for both "expression functions" and multi-statement function bodies, but
> with a preference given to multi-statement functions.

This is great data to have.

Something I found really interesting about this is that if you delete
Facebook and Netflix, this number goes up to 27%. In the MooTools
code, it's 40%. So either it just varies wildly depending on
programming style, or else library code has a greater need for
"expression functions" than application code.

> Of the "expression functions", only 1.5% return an object literal.  This
> suggests that BTF syntax should give preference to other forms, if there is
> a conflict.

This is good to know, too.


More information about the es-discuss mailing list