In Ruby 2.4 when we pass a block to a method, which further passes to another
method, Ruby creates a new Proc object by the given block before passing this proc to the
This creates unnecessary objects even when the block parameter is not accessed.
It also creates a chain of Proc objects when the block parameter is passed
through various methods.
Proc creation is one a heavyweight operation because
we need to store all local variables (represented by Env objects in MRI internal) in the heap.
Ruby 2.5 introduced a lazy proc allocation.
Ruby 2.5 will not create a Proc object
when passing a block to another method.
Insead, it will pass the block information.
If the block is accessed somewhere else, then it creates a Proc object by the given block.
This results in lesser memory allocation and faster execution.
As we can see, there is considerable improvement in execution time when
a block param is passed in Ruby 2.5.