Maybe I'm mistaken, but I think you can make your code faster as well...
    
    get '/' => sub {
        my $self = shift;
        my $sth = $self->db->prepare('SELECT id, content FROM updates');
        my %data;

        $sth->execute;

        while (my $r = $sth->fetchrow_arrayref) {
$data{$r->[0]} = $r->[1];
        }

        $self->render('invalid', %data);
    };

1) fetchrow_arrayref() is faster than fetchrow_hashref(). And it works, 
since you know the position of the columns because of the modified SELECT 
statement.
2) You only loop once. Which is at least twice as fast.
3) You never call stash, but pass the %data directly on to render() instead.

A completely different thing is that the code doesn't do any error 
checking. I would suggest using https://metacpan.org/pod/DBI#RaiseError

On Thursday, July 31, 2014 10:05:34 AM UTC+2, Peter Robb wrote:
>
> Wow !
>
> Very nice changes.. :-)
> And quick too.
> Thanks.
>
> Peter
> On 31 Jul 2014 02:00, "sri" <kra...@googlemail.com> wrote:
>
>> Dunno, thousands of method calls is generally not a smart thing to do, 
>>> optimizing for it seems wrong.
>>>
>>
>> I am trying a few things that appear to improver overall performance 
>> though, more proposals along those lines would be welcome.
>>
>>     
>> https://github.com/kraih/mojo/commit/157cea1a448bdc2b7768822bfbe944fd8530db62
>>
>> --
>> sebastian 
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Mojolicious" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/mojolicious/KTGEl4GjKkU/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> mojolicious+unsubscr...@googlegroups.com.
>> To post to this group, send email to mojolicious@googlegroups.com.
>> Visit this group at http://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to