Sean Russell <ser / germane-software.com> writes:

> > So refactor to decouple it
> > 
> >    Concept.create do |aConcept|
> ....
> >    end
> 
> This is really cool, Dave.  I'm still getting used to blocks, and what you 
> can do with them.  I just wish they weren't so slow :-/

In a context like this, where you're using blocks to guard resources,
speed of the block setup is likely to be dwarved by the stuff that
happens inside the block.

If you find blocks slow while looping, it might be because the blocks
are creating block-local variables. For example

    10000.times do |i|
       # do stuff with i
    end

runs significantly slower (10% or so) than

    i = nil
    10000.times do |i|
       # do stuff with i
    end

because in the first case, the block-local 'i' is created each time
around. (I suspect this is something that a clever person could
optimize using static analysis of the parsed nodes.)


Dave