Skip to content
This repository has been archived by the owner on Sep 13, 2017. It is now read-only.

Slight performance improvements #53

Closed
wants to merge 1 commit into from

Conversation

cheald
Copy link

@cheald cheald commented Nov 24, 2012

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

@cheald
Copy link
Author

cheald commented Nov 24, 2012

Hrm; Travis broke on JRuby, but it's because of an inability to use racc. I'm having trouble figuring out where my change might've broken that; the previous build passed just fine, so I'm somewhat confused there. Perhaps a Travis change? The previous build (which did pass) was almost a month ago.

@bogdan
Copy link
Contributor

bogdan commented Feb 4, 2013

Are you sure that this patch doesn't affect the runtime of gtg?

@cheald
Copy link
Author

cheald commented Feb 4, 2013

It's been a while since I was into this code, but I was measuring the culumative cost of the Journey code with request_profiler and kcachegrind. I'm travelling today, but when I get a chance, I'll run patched/unpatched and generate some useful numbers for inspection.

@sax
Copy link

sax commented Dec 12, 2013

@cheald Is this patch still valid? We're also looking into improving performance of Journey (particularly when rendering views with lots of links in Rails 3.2.14). Even a 9% improvement in load time would be nice 😄

@cheald
Copy link
Author

cheald commented Dec 12, 2013

I think it should be - I'm currently running it in production on our Rails 3.2.16 app.

@sax
Copy link

sax commented Dec 12, 2013

Awesome! We'll try it out.

@rafaelfranca
Copy link
Member

Journey is merged at Rails, and the stable branch is not maintained anymore since it is only for Rails 3.2 so I'm closing this pull request.

Thank you for the contribution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants