Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pre allocated buffer in Stash.xs #82

Merged
merged 1 commit into from
Oct 8, 2018
Merged

use pre allocated buffer in Stash.xs #82

merged 1 commit into from
Oct 8, 2018

Conversation

atoomic
Copy link
Collaborator

@atoomic atoomic commented Oct 3, 2018

convert_dotted_string can benefit from
a pre allocated buffer, avoiding the malloc + free.

convert_dotted_string can benefit from
a pre allocated buffer, avoiding the malloc + free.
@toddr
Copy link
Collaborator

toddr commented Oct 6, 2018

@atoomic do we have any metrics to show this is faster?

@atoomic
Copy link
Collaborator Author

atoomic commented Oct 8, 2018

performance stay very close, we avoid a malloc/free

                          Rate get_set_normal get_set_buffer
get_set_normal 29.675+-0.042/s             --          -2.1%
get_set_buffer 30.302+-0.023/s    2.11+-0.16%             --
                          Rate get_set_normal get_set_buffer
get_set_normal 22.538+-0.044/s             --          -1.9%
get_set_buffer 22.985+-0.038/s    1.99+-0.26%             --
use strict;
use warnings;
use lib qw( ./lib ../lib ../blib/lib ../blib/arch ./blib/lib ./blib/arch );
use Template::Constants qw( :status );
use Template;
use Template::Test;
use Template::Stash::XS;

my $count = 20;
my $data = {
    foo => 10,
    bar => {
        baz => 20,
    },
    something => {
      longer => {
         than => {
          usual => 12345
         }
      }
    },
};

use Benchmark::Dumb qw(:all);

my $stash = Template::Stash::XS->new($data);

print "... check\n";
match( $stash->get('bar.baz'), 20 );
match( $stash->get('something.longer.than.usual'), 12345 );
#match( $stash->get('str_eval_die'), '' );

match( $stash->get2('bar.baz'), 20 );
match( $stash->get2('something.longer.than.usual'), 12345 );

print "... done\n";

compare( "bar.baz" );
compare( 'something.longer.than.usual' );

exit;

sub compare {
  my ( $input ) = @_;

  cmpthese(
      0.01,    # 1% precision
      {   get_set_normal => sub {
              foreach my $i ( 1..1000 ) {
                $stash->get( $input ); 
                $stash->set( $input, $i ); 
                $stash->set( "$i.$i.$i.$i.$i.$i.$i.$i", $i ); 
              }
              
          },
          get_set_buffer => sub {
              foreach my $i ( 1..1000 ) {
                $stash->get2( $input ); 
                $stash->set2( $input, $i );
                $stash->set2( "$i.$i.$i.$i.$i.$i.$i.$i", $i );
              }

          },
      }
  );

}

@toddr toddr merged commit 931424f into abw:master Oct 8, 2018
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Nov 24, 2018
Upstream changes:
Version 2.28 - 11th October 2018
#------------------------------------------------------------------------

* Add and enable Travis CI to track GitHub Pull Requests

* Template is now using GitHub as the official Bug Tracker

* Nicolas R. fixed a circular reference in Template::Plugin::Filter
  abw/Template2#152

* Nicolas R. adjusted group regexes to not be greedy
  abw/Template2#94

* Nicolas R. added unit tests to cover regression from RT 91172
  abw/Template2#122

* Nicolas R. added support for template files having mtime=0
  abw/Template2#102

* Todd Rinaldo fixed rand calls with no args in Math plugin
  abw/Template2#155

* Todd Rinaldo corrected ttree 2.22 logic change
  abw/Template2#148

* Todd Rinaldo turned off automated testing for tests using optional modules
  abw/Template2#156

* Nicolas R. adjusted unit tests to not force Stash::XS

* Nicolas R. added a pre allocated buffer in Stash.xs to avoid malloc/free
  abw/Template2#82

* Nicolas R. optmized Template::Parser by avoiding a dummy sub
  abw/Template2#83

* Nicolas R. optimized Template:Directive by using index
  abw/Template2#84

* Nicolas R. adjust _dotop logic in Stash for perl 5.28 and earlier
  abw/Template2#81

* Todd Rinaldo documented VMethod method called 'item'
  abw/Template2#90

* Nicolas R. adjusted t/filter.t after recent switch to RFC3986
  abw/Template2#179

* Nicolas R. fixed warnings from t/cgi.t
  abw/Template2#178

* Ivan Krylov added STRICT option to ttree
  abw/Template2#81

* Kent Fredric fixed relative path handling in templates on Perl 5.26+
  abw/Template2#80

* Tom Delmas fixed some typo from documentation
  abw/Template2#76

* Matthew Somerville switched uri/url to use RFC3986
  updated the documentation to match the history.
  abw/Template2#35

* Sebastien Deseille used remove_tree helper to remove directories
  abw/Template2#67

* Nick Hibma - Add Sortkeys to DUMPER_ARGS
  abw/Template2#64

* E. Choroba added a warn on duplicate block name
  abw/Template2#61

* Jason Lewis fixed some typo in ttree.pod
  abw/Template2#58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants