public
Last active

This drastically speeds up require time on ruby 1.9 (17s down to 10s in our production rails app) , at the expense of disabling some edge case handling around autoloading. YMMV but it works for our rails app.

  • Download Gist
ruby_require_speed.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
From 2fb8432982b7e8ffc4c05f912f47cd9ca7261427 Mon Sep 17 00:00:00 2001
From: Xavier Shay <xavier@rhnh.net>
Date: Sun, 1 May 2011 10:25:18 +1000
Subject: [PATCH] Disable some edge cases in requiring to speed it up.
 
---
load.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
 
diff --git a/load.c b/load.c
index f8f0551..a14cc93 100644
--- a/load.c
+++ b/load.c
@@ -152,6 +152,7 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c
f = StringValuePtr(v);
if ((n = RSTRING_LEN(v)) < len) continue;
if (strncmp(f, feature, len) != 0) {
+ continue; // Pretty sure we don't need the behaviour below this line
if (expanded) continue;
if (!load_path) load_path = rb_get_expanded_load_path();
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
--
1.7.3.1

how drastically is drastically?

Cut about seven seconds off. Expect a blog post soon, I reckon I can do even better.

That's pretty drastic :)

a moderate sized rails app (based on number of gems in Gemfile) usually falls on the right hand size of this graph. (which is for a blank test case, not loading a rails app)

What OS are you running these tests on? I'm guessing *nix, but do you have the ability to test on Win7 even if through a setup like VirtualBox + http://rubyinstaller.org/downloads/

What's your require benchmarking code look like?

OSX, I don't have access to a windows machine at the moment, please do find the benchmark script at: https://gist.github.com/c8d0d422a9203e1fe492

I get similar sorts of performance gains too. Awesome!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.