Intel8080 emulator: Explicit coercion fix for Chakra

I was pointing out recently the disappointing performance of JavaScript in IE11. As a test I was using the Intel8080 emulator I wrote a few months ago. John-David Dalton (PM for the Chakra VM at Microsoft)  kindly investigated the issue and came back with a one line fix, improving largely the performance. This was the line causing the issue (line 44 in screen.js):

Which should be changed to:

Did you notice the integer coercion through the bitwise OR operator? Asm.js anyone? Coercing imagedata.width to integer helps Chakra infer the right types at runtime, which benefits performance. John gives the full explanation here, quick extract below:

The issue comes to Chakra incorrectly type specializing i as a float, partly because it lacks information about the DOM property imagedata.width. Explicitly coercing imagedata.width to an integer gives Chakra the info it needs to avoid the mix-up. I’ve filed a bug with Chakra to address this issue.

The great news is that the Chakra team logged this bug. Thanks again John-David! To highlight how much of a performance difference it makes, check the video below.

Again, just one line changed (left/without, right/with the change):

Intel8080 emulator: Explicit coercion fix for Chakra from Thibault Imbert on Vimeo.

Posted on July 29, 2013 by Thibault Imbert · 0 comments