diff options
author | Eric Wong <e@80x24.org> | 2019-12-18 03:36:45 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-12-19 04:07:50 +0000 |
commit | 7321c78ebdcaa7ce5f0f8383e07429827da0b718 (patch) | |
tree | 1877bacf3b43494f3d8a10e059fe3309953c6405 /lib/PublicInbox | |
parent | 3c313f9034aac96182e2efdc2f92c40803626f32 (diff) | |
download | public-inbox-7321c78ebdcaa7ce5f0f8383e07429827da0b718.tar.gz |
Spawning a new Perl interpreter for every test case means Perl has to reparse and recompile every single file it needs, costing us performance and development time. Now that we've modified our code to avoid global state, we can preload everything we need. The new "check-run" test target is now 20-30% faster than the original "check" target.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/TestCommon.pm | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 45306a5a..85cda031 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -60,7 +60,7 @@ sub require_git ($;$) { sub key2script ($) { my ($key) = @_; - return $key if $key =~ m!\A/!; + return $key if (index($key, '/') >= 0); # n.b. we may have scripts which don't start with "public-inbox" in # the future: $key =~ s/\A([-\.])/public-inbox$1/; @@ -101,9 +101,11 @@ sub key2sub ($) { my $f = key2script($key); open my $fh, '<', $f or die "open $f: $!"; my $str = do { local $/; <$fh> }; - my ($fc, $rest) = ($key =~ m/([a-z])([a-z0-9]+)\z/); - $fc = uc($fc); - my $pkg = "PublicInbox::TestScript::$fc$rest"; + my $pkg = (split(m!/!, $f))[-1]; + $pkg =~ s/([a-z])([a-z0-9]+)(\.t)?\z/\U$1\E$2/; + $pkg .= "_T" if $3; + $pkg =~ tr/-.//d; + $pkg = "PublicInbox::TestScript::$pkg"; eval <<EOF; package $pkg; use strict; @@ -111,6 +113,8 @@ use subs qw(exit); *exit = *PublicInbox::TestCommon::run_script_exit; sub main { +# the below "line" directive is a magic comment, see perlsyn(1) manpage +# line 1 "$f" $str 0; } |