views:

124

answers:

3

Are there any performance concerns related to the use of helpers like url_for and link_to in a Ruby on Rails application?

A: 

That's what caching is for.

Azeem.Butt
A: 

Yes. The use of dynamic URL generation (link_to, url_for) makes rails look up the routes table and that may consume time.

Having said that, these comes handy while generating a link that needs to send a delete/put request as it takes care of a lot of things internally. So I would say, use them but use them wisely, only when you know they save a lot of maintenance or some other reason for that matter.

Also, when it comes to performance, there are several techniques to enhance it. Rails caching (page, fragment, action) is one. Also, you might want to take a look at this question I had asked in the past.

Chirantan
Whats the -1 for?
Chirantan
+6  A: 

Yes, they are slower than hand-coding the links. See Stefan Kayes presentation on common performance problems with Rails (but realize that's from 2006 so it is a bit dated).

That said, I don't think it matters 99% of the time. Most sites never see the kind of traffic where this would matter at all, and if you do you can usually add caching to improve performance much more than getting rid of these helpers.

As always, benchmark your particular situation before optimizing.

Luke Francl
Luke beat me to it.I'll weigh in with a stronger opinion of "don't worry about it." Based on the tone of the question, I do not believe you're in a full-on optimization project phase. So, no, I don't think there are any performance *concerns* for you at this time. Reap the benefit of development speed while you can.The beauty of OSS is that by the time you need to start optimizing, the project may have already vastly improved the performance of a given method. In short, this will certainly not be your first performance concern, nor your heaviest hitting performance adjustment.
Barry Hess
Thanks Luke and Barry - we're definitely not in optimization mode - more of a discovery of best practices mode.
Trey
More to the point, I talked with some colleagues here and we're pretty sure there has been heavy optimization of those calls (routing optimization, really) since the article was written.
Barry Hess