The performance and compatibility of Function.prototype.bind and the resulting bound function objects has traditionally always been an issue in V8 (and thereby in Chromium based browsers and Node.js driven servers).
Consider the following simple test driver, which defines a (non-trivial) test function
foo and creates two bound functions
based on it, which both bind the receiver and the first argument to some primitive.
Now running this program with V8 tip-of-tree as of today requires a whopping 12,078ms to execute the test loop on a HP z620 work station running
Ubuntu 14.04. Looking at the performance profile, almost all the time is spend in the
boundFunction builtin (and the associated
helper runtime functions) that acts as a trampoline for bound functions. Looking closely into that function, we see that on every possible [[Call]]
path through the function (the [[Construct]] path uses the
%NewObjectFromBound C++ builtin), we bailout to C++ at least twice, once into
%BoundFunctionGetBindings, which returns a new Array with the bound target function, the bound this and the bound arguments, and once into
Running the test program above with my patch requires 239ms for the test loop, which is already a 50x improvement. There’s still some more cleanup to be done in order to land the patch (i.e. some API functions seem to require additional work to deal properly with the new representation of bound function objects), but the baseline results are already very promising. Once the baseline implementation is stabilized, we can start looking into optimizing bound functions, i.e. enable inlining of bound functions - which should boost this particular case to 100x improvement - and properly collecting and dealing with bound function type feedback.
I hope that this will in particular help web sites and web apps using React, because React makes heavy use of Function.prototype.bind. But for React we will also need to look into the performance of Function.prototype.bind itself and not only the throughput of bound functions, in order to reduce latency and startup time.