in reply to Can you speed up method calls by eliminating method dispatch?

You can, but you severely limit extensibility. Remember that in general you don't know if anybody inherits from your classes.

I don't know much about the speed implications, so I'd suggest you benchmark it. But I think that method lookup is cached, and that passing the arguments takes more time than the actual method dispatch.

  • Comment on Re: Can you speed up method calls by eliminating method dispatch?

Replies are listed 'Best First'.
Re^2: Can you speed up method calls by eliminating method dispatch?
by missingthepoint (Friar) on Jul 08, 2009 at 12:36 UTC

    OK - I was thinking I had a case where it might be appropriate, but your first comment made me realize that while I might be OK with limiting my code's extensibility, I would be making things harder for other people who want to inherit from my object. I guess I wasn't thinking very socially :)

    I will indeed benchmark it... I didn't know method lookup is cached, but it wouldn't surprise me considering the years of optimizations Perl 5 has had (is that documented anywhere? I can find NOTE: can directly uses Perl's internal code for method lookup, and isa uses a very similar method and cache-ing strategy in perlobj).


    The zeroeth step in writing a module is to make sure that there isn't already a decent one in CPAN. (-- Pod::Simple::Subclassing)