Three Monkeys, Three Typewriters, Two Days

October 18, 2009

Performance vs correctness tradeoffs

I've recently been running into a number of "benchmarks" where some rendering engines achieve better performance by simply doing the wrong thing because the right one would be "too slow". Here's a good example:

    // FIXME: This check is good enough for :hover + foo, but it is not good enough for :hover + foo + bar.
    // For now we will just worry about the common case, since it's a lot trickier to get the second case right
    // without doing way too much re-resolution.

and here's a testcase demonstrating that in this particular open-source rendering engine performance in selector matching and dynamic change handling is achieved at the expense of correctness:

  <style>
    div { color: red; }
    .foo + div + div { color: green; }
  </style>
  <body onload="document.getElementsByTagName('div')[0].className = 'foo'">
    <div></div>
    <div></div>
    <div>Text</div>

This is not exactly an isolated incident; a number of the performance issues I've run into recently in Gecko have had to do with correctly handling edge cases that this particular open-source engine happens to just not handle. I guess it's easier to do well on tests if you cheat.

More interestingly, Opera's performance on this sort of thing is still quite good, and I have yet to discover them cheating...

Posted by bzbarsky at October 18, 2009 12:39 PM