Ruby

Rails url_for is slow — some data comparison

There has been some discussion, though not a lot in print, of the fact that the Rails helper method url_for (which is also the basis for link_to and other frequently-used helpers) can be slow. This slowness stems from the process of generating routes, which takes longer as your routes.rb fills up.

As the Zvents site and traffic grow, we’re always looking for opportunities to improve performance. Our routes.rb has filled up a bit (nearly 40 entries), so I decided to do a little benchmarking to see if url_for was slowing us down, and if so, how much.

Here’s what I found.

I started with a page that has approximately 200 links generated with link_to (http://www.zvents.com/movies/theaters, though the number of links depends on your location). This is a lot of links, but that made it easier to run my tests. I wrapped each link_to call with a timing block, summed up the time, then took the average. Also, these tests were run on my development machine (MacBook Pro) in a Linux VM, under fairly heavy load.

Here’s the difference between calling link_to with a hash (causing a call to url_for), and calling it with a string (no call to url_for), average over roughly 1,000 measurements:

link_to WITH url_for: 6.8 ms

link_to WITHOUT url_for: 2.0 ms

That’s a big difference — almost 5 ms, or 3.4 times longer. And the cumulative effect on a page like the one tested, with nearly 200 links, is a total render time of almost one second more.

Obviously, the results will be very different on different machines, in different environments. I’d love to do a more general, scientific analysis, when I have some time. But for now, it’s just a little more information for you to use in trying to streamline your Rails apps.


General Performance and Scalability Rails Ruby
, , ,

If you enjoyed this post, make sure you subscribe to my RSS feed!

Comments

Tyler, Patrick Norton, Digital Life TV, Ajax, Ruby

Yes, these are all nouns we like here at Zvents. Well, they all came together tonight as Tyler talked AJAX and Ruby on Rails with Patrick Norton on Tech TV. You can download this segment at Ziff Davis’ site. I’d tell you when Tyler comes on, but you should watch the whole cool show. Thanks to Digital Life TV, and thanks to all the open-source guys who built these rockin’ projects!

-Tyler


Ajax Ruby
,

If you enjoyed this post, make sure you subscribe to my RSS feed!

Comments

Standing on the shoulders of open source giants

One of the important driving factors behind this whole “Web 2.0” thing is the ready availability of superb, production-class software and support for free. We remember the last dot-com wave – where every new startup was required to do the ritual self-flagellation of “Oracle and Sun, we know we need to scale” in order to get VC funding. Well, we don’t have Oracle, and we don’t have Sun (though those new Sun Opteron boxes are looking pretty good) but what we do have is enormous, unending gratitude for the folks behind the open source projects who made Zvents possible:

  • Linux (Red Hat and CentOS)
  • Ruby on Rails
  • lighttpd and Apache
  • Lucene and Nutch
  • MySQL
  • script.aculo.us
  • Openrico
  • Subversion
  • Trac
  • Typo

Yes, you guys really are changing the world. We love this new world, and are excited to be a part of it. We’ve only had a chance to contribute a few small patches during our mad rush to launch, but now that our baby is out the door we hope to spend more time giving back to the community. If you have any questions about how Zvents works, just ask!

Many, many thanks.

—The Zvents Team
Tyler, Tom, Ethan, Matt, Paul, Tim, Chris, and Allie


linux mysql open source Ruby Ruby on Rails
, , , ,

If you enjoyed this post, make sure you subscribe to my RSS feed!

Comments (1)