Three Monkeys, Three Typewriters, Two Days

October 23, 2009

Sane way to return arrays to JS from XPCOM methods

With bug 523817 fixed, you can now write an interface like this:

  void getSomething([optional] out unsigned long count,
                    [retval, array, size_is(count)] out whatever outArray);

and js consumers can do:

  var myArr = foo.getSomething();

to get an array without having to have a dummy argument for the length. Word of warning: this only works if the length has no required non-retval arguments after it, so put that length at the end, right before the retval array.

Posted by bzbarsky at 6:19 PM

October 18, 2009

It's snowing!

The rain turned to snow a few hours back. Too bad it's too warm for it to stick... First snow of the season, though!
Posted by bzbarsky at 3:10 PM

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 12:39 PM