|Subject:||Speed up Fatal by reducing calls to eval?|
I was looking at how to make perl5i load faster and did a profile run with Devel::NYTProf It revealed that 60ms (out of 160) was being spent in Fatal::_make_fatal(). 60ms might not seem a lot, but if I'm to promote perl5i as being something you slap onto every Perl program to generally improve the language I'm concerned about startup time. Of that 25ms is on a single line: $code = eval("package $pkg; use Carp; $code"); ## no critic # spent 2.56ms making 51 calls to Exporter::import, avg 50µs/call # spent 1.44ms making 63 calls to warnings::unimport, avg 23µs/call Another 10ms is here. $leak_guard = eval $leak_guard; ## no critic If the number of evals() or calls to _make_fatal() can be reduced then the load time for autodie can be drastically reduced. It seems that Fatal::import() is calling Fatal->_make_fatal() with all the same arguments except one, the function being made fatal. Perhaps instead of calling it one by one it can take a list and do them all at once, setting up the environment once and doing an eval once.