Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created May 1, 2011 01:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xaviershay/950154 to your computer and use it in GitHub Desktop.
Save xaviershay/950154 to your computer and use it in GitHub Desktop.
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 <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
@toolmantim
Copy link

how drastically is drastically?

@xaviershay
Copy link
Author

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

@toolmantim
Copy link

That's pretty drastic :)

@xaviershay
Copy link
Author

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)

@jonforums
Copy link

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?

@xaviershay
Copy link
Author

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

@fcheung
Copy link

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