Create a gist now

Instantly share code, notes, and snippets.

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.
From 2fb8432982b7e8ffc4c05f912f47cd9ca7261427 Mon Sep 17 00:00:00 2001
From: Xavier Shay <>
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)))

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 +

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:

fcheung commented May 13, 2011

I get similar sorts of performance gains too. Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment