rails/journey — pull request #53 by cheald (2012-11-24 09:53:19+00:00)
Title: Slight performance improvements

I've been working on reducing my app's boot time, and found that a lot of time was being spent in `Module#===`, which was primarily the fault of `Journey::GTG::Builder`'s case statements. `Module#===` has to walk the inheritance tree for a class when doing comparisons, so we can achieve better performance by avoiding it.

I refactored `Builder` so that rather than using `nullable?`, `firstpos`, and `lastpos` methods, those methods are now implemented on the individual nodes. This has the added benefit of being far more Rubyish. :)

Additionally, I implemented memoizations on the `Terminal` and `Cat` nodes, which improved the runtimes of their methods which return arrays by an order of magnitude according to ruby-prof.

The overall effect is that `ActionDispatch::Routing::Mapper::Resources#resources`' runtime is reduced from 968ms to 888ms in my app - about a 9% performance gain. Not blowing any hair back, but every little bit helps, and IMO it improves the code quality, as well. The performance gain should be more notable as the Journey AST increases in size.

I applied this against the 1-0-stable branch, but it also applies against and passes tests on master, as well