increpare/PuzzleScript — pull request #22 by shghs (2013-11-01 16:10:04+00:00)
Title: Performance improvement for ellipsis rule matching

This patch is a very minor change to avoid creating new arrays while matching ellipsis rules.

If run very often, the `result = result.concat(...)` lines in `matchCellRowWildCard()` can create lots of objects and lead to frequent GC pauses. Replacing these with `result.push.apply(result, ...)` (which does the same job without creating a new array) seems to remove a fair bit of GC stress.

I'm pretty sure the extra object allocations in `matchCellRowWildCard()` compared to `matchCellRow()` are the reason why `[ A ] [ A | ... | B ]` can sometimes be faster than `[ A | ... | B ]` alone, as discussed in [this forum thread](https://groups.google.com/d/msg/puzzlescript/vRMrhnt2cdE/Itw9oSTtYbYJ).

Using the code from Zeigfreid's slow example [here](http://www.puzzlescript.net/play.html?p=7254678), I took a short profile while pressing the right arrow key a few times:

![profile_before](http://i.imgur.com/d7Cm4Aq.png)

and again after my change:

![profile_after](http://i.imgur.com/7x4aaVO.png)

It seems to make a noticeable improvement, so you don't need to run a profiler to see the difference, but it's still not quite as fast as using `[ A ] [ A | ... | B ]`-style rules.