Here's a patch that makes Ruby interpretter slightly faster (~3%) by
optimizing a few commonly used functions (rb_call0, st_*, fix_equal):
*
http://zabor.org/taw/ruby-performance-patch-2007-02-21.patch.gz
And here's a blog post with details;
*
http://t-a-w.blogspot.com/2007/02/making-ruby-faster.html
Looks cool. Couple of comments...
1) if-then-else-switch... Not clear to me why it would be faster than
the switch. Also, most of that stuff is gone in ruby1.9. Seems you
were using ruby1.8, right? You should probably redo this patch
against yarv (see vm.c, for example).
2) Fixnum improvements. Kind of a good idea, but maybe a problematic
implementation. FIX2LONG() and similar are macros that allow hiding
the implementation details. This could allow in the future to have
Ruby treat Fixnums as true real objects (like Python), without
changing the source code. Currently, yes, they are pretty inefficient
as they do a shift each time, even when unneeded.
Removing the use of the macro may not be such a good idea, as
fix_equal like you have written it could break as soon as Fixnums are
no longer represented as longs, but as a class. You might work around
it by creating your own pseudo FIX2LONG_SANS_SHIFT() macro. That way,
if stuff changes, it will become obvious, and changing the macro to be
== to FIX2LONG() is all it should take.
Also, if I read your code correctly, fix_equal() as you presented it
is slightly different in that it does not check that the pointers are
the same when it is not a fixnum (this means something like a == a may
perform slower -- albeit I'll admit that is a weird case). I would
probably ask in the dev list why that check was needed in the first
place.
3) Judy is in general not faster than a hash lookup. It is just more
memory efficient.
Ruby might benefit from a better hash, thou, like google's
dense_hash_map (albeit it is C++ code, which Matz is
against).
4) You should probably make a separate patch for each improvement you
made, instead of all of them together. That will make it easier to
merge (and evaluate) them in case one of them is rejected but others
accepted.
Other than that, pretty cool. You should keep working on it and join
the ruby dev list to start merging your changes.
Here's also the docs for sending patches:
http://www.ruby-lang.org/en/community/ruby-core/