Skip Menu |

This queue is for tickets about the Params-Validate CPAN distribution.

Report information
The Basics
Id: 44637
Status: resolved
Priority: 0/
Queue: Params-Validate

People
Owner: Nobody in particular
Requestors: tokuhirom+cpan [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: micro optimization for Params::Validate
I found a micro optimization spot in the Params::Validate._get_called() is not needed in correct case. patch is here. http://gist.github.com/87046 This patch makes "validate(@_, {a => 1, b => 1})" 1.46x faster :) regards,
Subject: Re: [rt.cpan.org #44637] micro optimization for Params::Validate
Date: Sat, 28 Mar 2009 09:21:23 -0500 (CDT)
To: Tokuhiro Matsuno via RT <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Sat, 28 Mar 2009, Tokuhiro Matsuno via RT wrote: Show quoted text
> Sat Mar 28 03:30:11 2009: Request 44637 was acted upon. > Transaction: Ticket created by TOKUHIROM > Queue: Params-Validate > Subject: micro optimization for Params::Validate > Broken in: (no value) > Severity: Normal > Owner: Nobody > Requestors: tokuhirom+cpan@gmail.com > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=44637 > > > > I found a micro optimization spot in the Params::Validate._get_called() > is not needed in correct case. > > patch is here. > http://gist.github.com/87046 > > This patch makes "validate(@_, {a => 1, b => 1})" 1.46x faster :)
Why are you using the pure Perl version? The XS version is (last I checked) about twice as fast as the pure Perl version. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #44637] micro optimization for Params::Validate
Date: Sun, 29 Mar 2009 11:42:17 +0900
To: bug-Params-Validate [...] rt.cpan.org
From: Tokuhiro Matsuno <tokuhirom [...] gmail.com>
On Sat, Mar 28, 2009 at 11:21 PM, autarch@urth.org via RT <bug-Params-Validate@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=44637 > > > On Sat, 28 Mar 2009, Tokuhiro Matsuno via RT wrote: >
>> Sat Mar 28 03:30:11 2009: Request 44637 was acted upon. >> Transaction: Ticket created by TOKUHIROM >>       Queue: Params-Validate >>     Subject: micro optimization for Params::Validate >>   Broken in: (no value) >>    Severity: Normal >>       Owner: Nobody >>  Requestors: tokuhirom+cpan@gmail.com >>      Status: new >> Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=44637 > >> >> >> I found a micro optimization spot in the Params::Validate._get_called() >> is not needed in correct case. >> >> patch is here. >> http://gist.github.com/87046 >> >> This patch makes "validate(@_, {a => 1, b => 1})" 1.46x faster :)
> > Why are you using the pure Perl version? The XS version is (last I > checked) about twice as fast as the pure Perl version. > > > -dave > > /*============================================================ > http://VegGuide.org               http://blog.urth.org > Your guide to all that's veg      House Absolute(ly Pointless) > ============================================================*/ > >
XS version is not a fast in my environment. benchmark score is here: -- 0.91 pp ver 5.010000 pp ver Benchmark: timing 100000 iterations of complex, simple... complex: 9 wallclock secs ( 8.58 usr + 0.00 sys = 8.58 CPU) @ 11655.01/s (n=100000) simple: 5 wallclock secs ( 5.19 usr + 0.00 sys = 5.19 CPU) @ 19267.82/s (n=100000) -- 0.91 xs ver 5.010000 xs ver Benchmark: timing 100000 iterations of complex, simple... complex: 8 wallclock secs ( 7.47 usr + 0.00 sys = 7.47 CPU) @ 13386.88/s (n=100000) simple: 5 wallclock secs ( 5.28 usr + 0.00 sys = 5.28 CPU) @ 18939.39/s (n=100000) -- 0.91 pp ver + my patch 5.010000 pp ver Benchmark: timing 100000 iterations of complex, simple... complex: 8 wallclock secs ( 7.60 usr + 0.00 sys = 7.60 CPU) @ 13157.89/s (n=100000) simple: 4 wallclock secs ( 4.15 usr + 0.00 sys = 4.15 CPU) @ 24096.39/s (n=100000) looks like a pp ver + my patch is faster than xs version.why?? how to get a 2x score? followings are benchmarks script. use strict; use warnings; use Params::Validate; use Benchmark ':all'; use UNIVERSAL::which; print "$]\n"; print $INC{'Params/ValidateXS.pm'} ? "xs ver\n" : "pp ver\n"; timethese( 100000 => { simple => sub { simple(a => 1, b => 1) }, complex => sub { complex(a => bless({}, 'Foo'), b => bless([], 'main')) }, }, ); sub simple { my %args = validate( @_, { a => 1, b => 1, }, ); 1; } sub complex { my %args = validate( @_, { a => { isa => 'Foo', }, b => { can => 'complex', }, }, ); 1; }
Subject: Re: [rt.cpan.org #44637] micro optimization for Params::Validate
Date: Sat, 28 Mar 2009 22:07:38 -0500 (CDT)
To: "tokuhirom [...] gmail.com via RT" <bug-Params-Validate [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Sat, 28 Mar 2009, tokuhirom@gmail.com via RT wrote: Show quoted text
> XS version is not a fast in my environment. > > benchmark score is here: > -- 0.91 pp ver > 5.010000 > pp ver > Benchmark: timing 100000 iterations of complex, simple... > complex: 9 wallclock secs ( 8.58 usr + 0.00 sys = 8.58 CPU) @ > 11655.01/s (n=100000) > simple: 5 wallclock secs ( 5.19 usr + 0.00 sys = 5.19 CPU) @ > 19267.82/s (n=100000) > > -- 0.91 xs ver > 5.010000 > xs ver > Benchmark: timing 100000 iterations of complex, simple... > complex: 8 wallclock secs ( 7.47 usr + 0.00 sys = 7.47 CPU) @ > 13386.88/s (n=100000) > simple: 5 wallclock secs ( 5.28 usr + 0.00 sys = 5.28 CPU) @ > 18939.39/s (n=100000) > > -- 0.91 pp ver + my patch > 5.010000 > pp ver > Benchmark: timing 100000 iterations of complex, simple... > complex: 8 wallclock secs ( 7.60 usr + 0.00 sys = 7.60 CPU) @ > 13157.89/s (n=100000) > simple: 4 wallclock secs ( 4.15 usr + 0.00 sys = 4.15 CPU) @ > 24096.39/s (n=100000) > > looks like a pp ver + my patch is faster than xs version.why?? > how to get a 2x score?
I think there's a couple things going on here. First, the validations you're doing are pretty simple, even the complex one. The more validation you do per call, the more noticeable the XS version is. Second, I probably misremembered the actual speed increase. I think it's maybe more like 1.5x as fast (or a little more) in some cases. Also, the last time I did a lot of benchmarking was when the XS was released, back in 2003. It's quite possible that on a modern computer, with a modern Perl, things have changed. I did try applying your patch, but it didn't seem to make much difference. There's also a benchmark in the Params::Validate repo https://svn.urth.org/svn/Params-Validate/trunk/ What's interesting is that for the simplest validations in that benchmark, pure Perl is _faster_. For the more complex ones, the XS version is anywhere from 25-60% faster. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/