I'm not sure what you mean by "once and losing the method cache". Perhaps there's something I didn't read in the thread.
AUTOLOAD tends to be slow as Perl must walk through the inheritance tree (if any beyond UNIVERSAL) and search for an appropriate method. Then Perl goes back to the top and looks for AUTOLOAD methods. If it finds one (and you hope it's the right one if there's more than one), then Perl has to execute your AUTOLOAD code prior to getting to the correct method call. Whether or not this is a significant hit depends upon the how frequently AUTOLOAD is going to get called in your application.
| [reply] |
Perl has a cache that it uses to avoid walking the inheritance tree, basically if you looked in this package and found the method over there, then it just returns the same method the next time. This speeds things up, but you need to remove the cache if anything happens that could make it invalid - such as defining a function somewhere. It will then build up again.
So if you use an AUTOLOAD that autogenerates methods, then every time you hit that AUTOLOAD you throw away the method cache and have to start generating it again. Depending on your program's profile, this can be significant overhead.
| [reply] |
Does defining a function really clear the cache, or just defining a named function? Defining a function should have no effect, just the modification of the symbol table that comes from defining named functions.
| [reply] |