[html-formfu] Form->process() performance - how to investigate

Stephen Shorrock stephen.shorrock at gmail.com
Wed Jan 8 16:42:14 GMT 2014


Happy New Year etc...

I'm hoping that someone is able to offer some advice for the best way to
optimize a form.

I currently have a rather complex form where there are  a dynamic number of
rows of input options (repeatable block) and in each row ~ 25 input

The trouble is that via a Catalyst app it seems to take n seconds to
process the form ($form->process()), where n is the number of rows.

Outside of catalyst the processing takes a consistent 1 second (admittedly
without any form data).

Has anyone got any tips on how to investigate the cause of the lag in-situ
of a Catalyst application?

Or perhaps be able to offer any insights to where my inefficiencies may lie
(please see below for more details). I notice using NYTProf that
nested_names and nested_name are heavily called. What would be the best way
to reduce these calls?

Thanks in advance


my form is as follows:

form_error_message_xml: Your sheet contained errors please review and re
auto_constraint_class: constraint_%t
  - type: Block
     - type: Block
       tag: table
         class: triss_input campl-vertical-stacking-table
        - type: Hidden
          name: rows
          value: 10
        - type: Repeatable
          name: entries
          nested_name: entry
           - type: Block
             tag: tr
              - type: Weeklyusage
                name: usage
                id: weekusage
                auto_block_id: 'rt_%r'
        - type: Block
          tag: tr
            - type: Block
              tag: td
                colspan: 10
                - type: Textarea
                  label: Notes
                  name: tsh_notes
                    style: "width:100%; height:5em"
  - type: Submit
    value: Add row
    name: submit_add_row
      class: left_float
  - type: Submit
    value: Save for later
    name: submit_save
      class: left_float

My rather complex row elements is defined as:

package HTML::FormFu::Element::

use Moose;
use MooseX::Attribute::Chained;
extends 'HTML::FormFu::Element::Block';

use Moose::Util qw( apply_all_roles );

#This element will create four table row for:
#Half hour, hour, half day, day selects

sub process {
    my ( $self, @args ) =3D @_;


    #should this also do the adding after the filtering etc?

#    return $self->SUPER::process(@args);

sub _add_elements {
    my ($self) =3D @_;

    $self->_elements( [] );


sub _add_week_blanks {
    my ($self) =3D @_;

    my $tr =3D $self->element('Block');
    foreach ((1..7)){
    my $td =3D $tr->element('Block');

sub _add_week_hours {
    my ($self) =3D @_;

    my $td =3D $self->element('Block');

    my $options_equipment=3D[];
    $td->element( {
            type       =3D> 'Select',
            name       =3D> "_equipment_",
            #id         =3D> "_equipment_",
            options    =3D> $options_equipment,
            constraints =3D>
            attributes =3D> { class=3D>"_equipment_ width10", empty_first=

        } );
    my $td1 =3D $self->element('Block');

    my $options_account=3D[];
    $td1->element( {
            type       =3D> 'Select',
            name       =3D> "_account_",
            options    =3D> $options_account,
           attributes =3D> { class=3D>"_account_ width10"},##

        } );

    my $options=3D[{value=3D>"",label=3D>""}];
    map { push @{$options}, {'value'=3D>$_,'label'=3D>$_.".0 hrs"} } (1..24=
    my $options_half=3D[{value=3D>"",label=3D>""}];
    map { push @{$options_half}, {'value'=3D>$_*0.5,'label'=3D>$_*0.5." hrs=
"} }
    my $options_mins=3D[{value=3D>"",label=3D>""}];
    map { push @{$options_mins}, {'value'=3D>$_*10,'label'=3D>$_*10.0." min=
} (1..48);
    my $options_fullday=3D[{value=3D>"",label=3D>""},{'value'=3D>'1','label=
    my $options_halfday=3D[{value=3D>"",label=3D>""},{'value'=3D>'1','label=
day'},{value=3D>'2','label'=3D>'1 day'}];

    foreach ((1..7)){

        my $td =3D $self->element('Block');

        $td->element( {
            type       =3D> 'Select',
            name       =3D> "_hours_".$_,
            options    =3D> $options,
            constraints =3D> ['Number'],
            attributes =3D> {class=3D>"_hours_ hide width8"},

        } );

    my $element1 =3D $td->element( {
            type       =3D> 'Select',
            name       =3D> "_halfhours_".$_,
            options    =3D> $options_half,
            constraints =3D> ['Number'],
            attributes =3D> {class=3D>"_halfhours_ hide width8"},

    } );

    my $element2 =3D $td->element( {
            type       =3D>  'Select',
            name       =3D> "_fullday_".$_,
            options    =3D> $options_fullday,
            constraints =3D> ['Number'],
            attributes =3D> {class=3D>"_fullday_ hide width8"},

    } );

    my $element3 =3D $td->element( {
            type       =3D> 'Select',
            name       =3D> "_halfday_".$_,
            options    =3D> $options_halfday,
            constraints =3D> ['Number'],
            attributes =3D> {class=3D>"_halfday_ hide width8"},

    } );

    my $element4 =3D $td->element( {
            type       =3D> 'Select',
            name       =3D> "_mins_".$_,
            options    =3D> $options_mins,
            constraints =3D> ['Number'],
            attributes =3D> {class=3D>"_mins_ hide width8"},

    } );


    $self->element('Block')->tag('td')->element( {
            type        =3D> 'Text',
            name        =3D> "_total_",
            attributes  =3D> {size=3D>10,
        plugins =3D> [{type=3D>'TRISS::TotalTime',
fieldlist=3D>['1','2','3','4','5','6','7'], classof=3D>'_equipment_'} ],

    } );


sub render_data {


    #unhide any of the selects for equipment that has been selected

    #append the types to our option equipment option values

    return shift->render_data_non_recursive(@_);

sub render_data_non_recursive {
    my ( $self, $args ) =3D @_;

    my $render =3D $self->SUPER::render_data_non_recursive( {
            elements =3D> [ map { $_->render_data } @{ $self->_elements } ],
            $args ? %$args : (),
        } );

    return $render;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20140108/8d=

More information about the HTML-FormFu mailing list