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

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


Hi,

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
elements.

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

Stephen


my form is as follows:


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


My rather complex row elements is defined as:


package HTML::FormFu::Element::
Weeklyusage;

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 @_;

    $self->_add_elements();

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

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

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

    $self->_elements( [] );


    $self->_add_week_hours();
}

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

    my $tr =3D $self->element('Block');
    $tr->tag('tr');
    $tr->attributes({'style'=3D>''},{'class'=3D>'week_blank'});
    foreach ((1..7)){
    my $td =3D $tr->element('Block');
    $td->tag('td');
    }
}

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

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

    my $options_equipment=3D[];
    $td->element( {
            type       =3D> 'Select',
            name       =3D> "_equipment_",
            #id         =3D> "_equipment_",
            options    =3D> $options_equipment,
            constraints =3D>
[{type=3D>'TRISS::AllOrNoneRepeatable',others=3D>["_account_","_equipment_"=
],message=3D>"*"}],
            attributes =3D> { class=3D>"_equipment_ width10", empty_first=
=3D>1},#

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


    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=
"} }
(1..48);
    my $options_mins=3D[{value=3D>"",label=3D>""}];
    map { push @{$options_mins}, {'value'=3D>$_*10,'label'=3D>$_*10.0." min=
s"}
} (1..48);
    my $options_fullday=3D[{value=3D>"",label=3D>""},{'value'=3D>'1','label=
'=3D>'1
day'}];
    my $options_halfday=3D[{value=3D>"",label=3D>""},{'value'=3D>'1','label=
'=3D>'0.5
day'},{value=3D>'2','label'=3D>'1 day'}];

    foreach ((1..7)){

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

        $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,
readonly=3D>'readonly',class=3D>"width14"},
        plugins =3D> [{type=3D>'TRISS::TotalTime',
fieldlist=3D>['1','2','3','4','5','6','7'], classof=3D>'_equipment_'} ],

    } );



    return;
}


sub render_data {

    #TODO:

    #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=
34e133/attachment.htm


More information about the HTML-FormFu mailing list