From: Eric Mahurin Date: 2006-07-31T12:57:16+09:00 Subject: bypassing method lookup/call overhead From performance testing that I've looked at with a C extension, it looks like the overhead of method lookup and calling (rb_funcall) is a major bottleneck. Is there an accepted way to precalculate the final C function pointer (or something close to it) and use this when you are dealing with a constant variable or even variable with a constant class? Looking in eval.c, it looks like method_call would do a partial job of this (at least bypassing the method lookup) using a Method object. Unfortunately, this isn't made available in ruby.h. Even better would be a way to do this in ruby. I tried two possibilities: a. Use #method to look up the method and #call it later. Possibly useful for constant variables. b. Use #method, convert it to a block with unary &, and have another method yield to it. Only useful if to speed up one method call of a constant variable. Unfotunately, both of these were slower. The block/yield experiment was several times slower. Based on the fact that a block is much closer to a function pointer (not a full Proc object), I would have hoped this would be faster. I guess converting the method to a block wasn't much different than #call'ing the method from a separate block. Any better ideas?