Reputation: 21
Are there any performance concerns related to the use of helpers like url_for and link_to in a Ruby on Rails application?
Upvotes: 1
Views: 717
Reputation: 15634
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.
Upvotes: 1
Reputation: 31444
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.
Upvotes: 6