use HTTP::Headers::Fast->flatten introduced 0.20 #540

Merged
merged 1 commit into from Nov 24, 2015

Projects

None yet

3 participants

@kazeburo
Contributor

HTTP::Headers::Fast->flatten was introduced in tokuhirom/HTTP-Headers-Fast#8. flatten is shortcut method for building PSGI compatible header array. This PR uses that.

benchmark. Would be 10% faster.

master

% perl bench.pl
Benchmark: running bench_hello for at least 3 CPU seconds...
bench_hello:  4 wallclock secs ( 3.22 usr +  0.00 sys =  3.22 CPU) @ 60104.35/s (n=193536)
               Rate bench_hello
bench_hello 60104/s          --

This PR

% perl -Ilib bench.pl
Benchmark: running bench_hello for at least 3 CPU seconds...
bench_hello:  4 wallclock secs ( 3.30 usr +  0.01 sys =  3.31 CPU) @ 66011.48/s (n=218498)
               Rate bench_hello
bench_hello 66011/s          --

benchmark script

use HTTP::Request::Common;
use HTTP::Message::PSGI;
use Plack::Response;
use Benchmark qw/cmpthese timethese/;

my $env = req_to_psgi(GET "/");
my $app = sub {
    my $res = Plack::Response->new(200);
    $res->content_type('text/plain');
    $res->body("Hello World\n");
    $res->finalize;
};

cmpthese(timethese(0,{
    'bench_hello' => sub {
        $app->($env);
    }
}));


@miyagawa miyagawa merged commit 0a69c4b into plack:master Nov 24, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@zebardy
zebardy commented on 54c0e25 Dec 4, 2015

This change breaks compatibility with HTTP::Headers. HTTP::Headers->flatern returns an array, not an array reference. Therefore when HTTP::Headers are used the size of the flattened HTTP::Headers object will be returned instead of an array reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment