From: Daniel Sheppard Date: 2006-02-14T15:59:08+09:00 Subject: Re: FasterGenerator (#66) > I'm pretty sure they learned the same lesson changing the standard > library. Have a look at these commit messages: > > * lib/generator.rb: uses Mutex instead of Thread.critical. > [ruby-dev:28184] > > Then later: > > Sorry, reverted. Mutex is damn slow..... > > :) > > James Edward Gray II Which makes perfect sense, since Mutex is simply wrapping around Thread.critical, Thread.stop and Thread.wakeup. Mutex, as simple as it is, is overkill for what you're trying to do here (switch between two threads in a deterministic manner). Since the number of threads is fixed, you don't need to keep the thread list in an array, and you can drop a couple of other checks because you know all the calling code. If raw speed is your goal, relying on any pure ruby will never get you faster than just inlining the subset of that code that you're interested in using - even if you're just completely duplicating the logic, it's going to be that slightest bit faster as you've reduced the number of messages sent - and I think it's safe to say that reducing the total number of message sends will always make your program faster, barring any change in IO. That's not to say that inlining bastardised versions of other libraries is a good idea... except where it is. Now, if somebody went and implemented the thread standard library as a C extension, then it might be worth using in this context... or maybe not.