Question

I'm using HTML::FormHandler with my mod_perl/Catalyst app to generate a form for my users. It works fine, the only problem is that it slows down page load time by a lot. Here is my subroutine that creates the new form:

sub edit : Chained('base') PathPart Args(0) {
    my ( $self, $c ) = @_; 

    my $form = myapp::Form::Account::Edit->new;

    #validation stuff, etc
    #...
}

Just adding in the one line "my $form = myapp::Form::Account::Edit->new;" causes my page load time to go from 50ms up to anywhere from 500-1000ms. I know some people could argue that 500-1000ms page load time for a site is still good, but I'm expecting this site to get high traffic, and right now it's taking that long for a page to load with just one user. I know that HTML::FormHandler is big, as it uses Moose, but after it's loaded once shouldn't it already be loaded? Is there any way I can speed up long this is taking, or is this just the price of using HTML::FormHandler? I'd really like to keep using it if I could, as it makes my life as the coder much easier :)

Was it helpful?

Solution

You can also build the form in a Moose attribute for the controller, making the form persistent. This means that information from the last request will still be in the form object and will be cleared at the beginning of the next request (or could be cleared by the programmer after the form is rendered). You also have to clear any additional attributes you've added to the form, or ensure that they're set on every 'process' call.

OTHER TIPS

You could load a module with mod_perl, before your apps calling it.

http://www.conceptsolutionsbc.com/perl-articles-mainmenu-41/29-perl-and-apache/55-modperl-part-2-pre-loading-perl-modules

#put his to apache config file:
PerlModule HTML::FormHandler;

EDIT:

To speed up thing at runtuime you could use memoize to speed up things.

Create a new sub, called get_form_handler and memoize its output.

You could even use Cache-FastMmap to store this object (output) at once and share between proceses.

Regards,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top