Skip to main content
100%

EventsSpeedTests

✓ Published0🌍 Public
HHypercubed
Last edited Oct 17, 2015
Created on Oct 12, 2015

This example demonstrates how a single property added to one function—but not all functions—can trigger V8’s “failed to optimize dispatch” warning in a hot loop. It shows the impact of monomorphic versus polymorphic call-sites for `Function.prototype.apply` when dispatching to multiple callbacks. The code runs 2 million iterations of a `dispatch` function that invokes two callbacks, comparing an unoptimized case, a bound-function variant, and a fixed version using `.bind(0)` to enforce a monomorphic apply site. The included HTML interface and Node command-line tests let users measure execution time differences across the three approaches.

AI-generated description

"Not optimized: Bad value context for arguments value"

Adding a property to one function, but not all functions, causes Not optimized flag on function containing Function.prototype.apply.

Cause

"V8 only recognizes monomorphic .apply call-sites" - @mraleph

Example

See example.js

Fixes

Test in node

node --trace_opt --trace_deopt example.js | grep "failed to optimize dispatch"

Test in browser

jspm install
http-server  # open http://localhost:8080/

Similar vizzes