Live data from Hacker News

Apple Lossless Decoder in Coffeescript

github.com

1–10 of 26 posts

Re: Apple Lossless Decoder in Coffeescript

#6

@devongovett: Have you considered pushing the annotated source for this to your "gh-pages" branch? It would make for a great read.

Would take quite some time annotating the source, not really our first priority. (We have more codecs on our hitlist)

But if someone wants to do it, I think both me and @devongovett would be ready to help out a bit.

(We usually hang out in #ofmlabs on freenode, if someone wants to speak with us)

Re: Apple Lossless Decoder in Coffeescript

#9

devongovett/jensnockert: what was your experience with using CoffeeScript for such low level code? Did you need to consciously avoid certain CoffeeScript features that could negatively impact performance?

Mostly avoided the regular for loops, replacing them with `for ... by 1`, to make sure the compiler knows in which direction to iterate.

Otherwise it is pretty similar to javascript, most coffeescript constructs map pretty simply down to javascript, so optimization tips for one language mostly applies to the other.

Re: Apple Lossless Decoder in Coffeescript

#10

devongovett/jensnockert: what was your experience with using CoffeeScript for such low level code? Did you need to consciously avoid certain CoffeeScript features that could negatively impact performance?

Overall positive, but as with any programming language, you have to be careful sometimes. For example, the for loop in CoffeeScript can be slow if you aren't careful:

    for i in [0...10]
      doSomething()
is slower than

    for i in [0...10] by 1
      doSomething()
because of the way it is compiled, so we always include the `by 1` as an optimization.

Another one is that if you have a function and the last thing in that function is a loop of some kind, CoffeeScript will try to return an array from that function collecting the results of the loop. So we explicitly put a return statement at the end of the function to avoid this and the performance penalties.

There are probably a few more to be careful of, but overall performance characteristics are similar to JS. I'm sure Jens has some thoughts too, but overall I think it was a positive experience.

Post reply on HN