Subject: | performance suggestion: cache package data in the application object |
Cees,
I emulated the package-variable handling logic in this in
CGI::Application::Plugin::Config::Perl, so I can avoid reading the
config file only once per request in persistent environments.
In benchmarking variations of my own code, I found a design change which
I think would apply to this as well (although I haven't benchmarked this
plugin).
The optimization I made was to cache the packaged-stored data in the
CGI::Application object, so that repeated requests for the stored data
are found quicker.
This probably matters more for a config plugin, which may get several
calls to config() over the course of the request, while the TT plugin
may get only one tt_process(). In my plugin, it was a 40x improvement
for calls to config().
The recipe was simple: At the place that data is set in the package,
also set it in the application object.