Slashdot Mirror


Internet Explorer 9 Caught Cheating In SunSpider

dkd903 writes "A Mozilla engineer has uncovered something embarrassing for Microsoft – Internet Explorer is cheating in the SunSpider Benchmark. The SunSpider, although developed by Apple, has nowadays become a very popular choice of benchmark for the JavaScript engines of browsers."

4 of 360 comments (clear)

  1. Re:Benchmarks by TheRaven64 · · Score: 5, Informative

    There is a difference between optimising for a benchmark and cheating at a benchmark. Optimising for a benchmark means looking at the patterns that are in a benchmark and ensuring that these generate good code. This is generally beneficial, because a well-constructed benchmark is representative of the kind of code that people will run, so optimising for the benchmark means that common cases in real code will be optimised too. I do this, and I assume that most other compiler writers do the same. Cheating at a benchmark means spotting code in a benchmark and returning a special case.

    For example, if someone is running a recursive Fibonacci implementation as a benchmark, a valid optimisation would be noting that the function has no side effects and automatically memoising it. This would turn it into a linear time, rather than polynomial time, function, at the cost of increased memory usage. A cheating optimisation would be to recognise that it's the Fibonacci sequence benchmark and replaces it with one that's precalculated the return values. The cheat would be a lot faster, but it would be a special case for that specific benchmark and would have no impact on any other code - it's cheating because you're not really using the compiler at all, you're hand-cmpiling that specific case, which is an approach that doesn't scale.

    The Mozilla engineer is claiming that this is an example of cheating because trivial changes to the code (adding an explicit return; at the end, and adding a line saying true;) both make the benchmark much slower. I'm inclined to agree. The true; line is a bit difficult - an optimiser should be stripping that out, but it's possible that it's generating an on-stack reference to the true singleton, which might mess up some data alignment. The explicit return is more obvious - that ought to be generating exactly the same AST as the version with an implicit return.

    That said, fair benchmarks are incredibly hard to write for modern computers. I've got a couple of benchmarks that show my Smalltalk compiler is significantly faster than GCC-compiled C. If you look at the instruction streams generated by the two, this shouldn't be the case, but due to some interaction with the cache the more complex code runs faster than the simpler code. Modify either the Smalltalk or C versions very slightly and this advantage vanishes and the results return to something more plausible. There are lots of optimisations that you can do with JavaScript that have a massive performance impact, but need some quite complex heuristics to decide where to apply them. A fairly simple change to a program can quite easily make it fall through the optimiser's pattern matching engine and run in the slow path.

    --
    I am TheRaven on Soylent News
  2. Re:Benchmarks by Nutria · · Score: 5, Informative

    Fear not, for I have RTFA and the original article that the digitizor article is based on.

    Fortunately for the ethics of Mozilla, the named Mozilla engineer (Rob Sayre) never claimed that IE9 cheated. Instead, he diplomatically refers to it as a "oddity" and "fragile analysis" and filed a bug w/ MSFT.

    http://blog.mozilla.com/rob-sayre/2010/09/09/js-benchmarks-closing-in/M
    http://blog.mozilla.com/rob-sayre/2010/11/16/reporting-a-bug-on-a-fragile-analysis/

    So, blame Digitizor and ycombinator for putting words in Rob Sayre's mouth.

    --
    "I don't know, therefore Aliens" Wafflebox1
  3. Re:Benchmarks by BZ · · Score: 5, Informative

    1) If you actually read the article, you may have noticed that the engineer is named. It's
            right there there at the beginning of paragraph 2: "While Mozilla engineer Rob Sayre"
    2) The "cheating" stuff is all from the Hacker News thread and the fucking articl. I
            suggest you further read item 1 under "Further Readings" on the fucking article, which
            is what Rob actually wrote. The link is: http://blog.mozilla.com/rob-sayre/2010/11/16/reporting-a-bug-on-a-fragile-analysis/

    Just to save you the trouble of reading it, if don't want to, it's pretty clear that IE9 is eliminating the heart of the math-cordic loop as dead code. It _is_ dead code, so the optimization is correct. What's weird is that very similar code (in fact, code that compiles to identical bytecode in some other JS engines) that's just as dead is not dead-code eliminated. This suggests that the dead-code-elimination algorithm is somewhat fragile. In particular, testing has yet to turn up a single other piece of dead code it eliminates other than this one function in Sunspider. So Rob filed a bug about this apparent fragility with Microsoft and blogged about it. The rest is all speculation by third parties.

  4. Re:Embarassing? by chrb · · Score: 5, Informative

    Did you look at the diffs? The addition of the "true;" operation should make absolutely no difference to the output code. It's a NOP. The fact that it makes a difference indicates that either something fishy is going on, or there is a bug in the compiler that fails to recognise "true;" or "return (at end of function)" as being deadcode to optimise away, and yet the compiler can apparently otherwise recognise the entire function as deadcode. Just to be clear, we are talking about a compiler that can apparently completely optimise away this whole function:

    function cordicsincos() {
            var X;
            var Y;
            var TargetAngle;
            var CurrAngle;
            var Step;

            X = FIXED(AG_CONST); /* AG_CONST * cos(0) */
            Y = 0; /* AG_CONST * sin(0) */

            TargetAngle = FIXED(28.027);
            CurrAngle = 0;
            for (Step = 0; Step CurrAngle) {
                            NewX = X - (Y >> Step);
                            Y = (X >> Step) + Y;
                            X = NewX;
                            CurrAngle += Angles[Step];
                    } else {
                            NewX = X + (Y >> Step);
                            Y = -(X >> Step) + Y;
                            X = NewX;
                            CurrAngle -= Angles[Step];
                    }
            }
    }

    but fails to optimise away the code when a single "true;" instruction is added, or when "return" is added to the end of the function. Maybe it is just a bug, but it certainly is an odd one.

    This shows the dangers of synthetic non-realistic benchmarks. I was amused to read Microsoft's comments on SunSpider: "The WebKit SunSpider tests exercise less than 10% of the API’s available from JavaScript and many of the tests loop through the same code thousands of times. This approach is not representative of real world scenarios and favors some JavaScript engine architectures over others." Indeed.

    btw the Hacker News discussion is more informative.