I was porting a script to a module and noticed it kept getting slower. The script could initialize its expensive data structure once at the top and be done with it, but in order to encapsulate, the module was calling the function several times. I remembered the core module Memoize and added one line to the top of the program and now it runs fast again, 4x faster than without Memoize!

use Memoize; memoize('some_sub');

Only 1.5 seconds to start a program that was taking 6 seconds!

Replies are listed 'Best First'.
Re: use Memoize;
by Athanasius (Archbishop) on Jul 17, 2018 at 02:45 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.