PPI
PPI copied to clipboard
track currently active features while scanning
... instead of repeatedly scanning backwards for all feature enabling/disabling statements every time we need to know the current feature set. In my tests, this massively speeds up parsing of big documents/source files.
Fixes #309.
Demonstration:
use v5.36;
use PPI::Document;
my $source = "use v5.36;\n";
for my $i (0 .. 399) {
my $sub = "sub foo_$i(\$x, \$y) {\n";
for my $j (0 .. 29) {
$sub .= " g(\$x->[\$y]" . join('', map ", $_", 1 .. $j) . ");\n";
}
$sub .= "}\n";
$source .= "$sub\n";
}
say "parsing " . length($source) . " chars of code ...";
my $doc = PPI::Document->new(\$source);
say "done";
With PPI 1.284:
$ time perl try.pl
parsing 819901 chars of code ...
done
real 0m37.017s
user 0m36.700s
sys 0m0.310s
With this patch:
$ time perl -I"$HOME/Projects/PPI/lib" try.pl
parsing 819901 chars of code ...
done
real 0m7.387s
user 0m7.170s
sys 0m0.217s