NAME

Perl::Critic::PPIx::Optimized

SYNOPSIS

use Perl::Critic::PPIx::SpeedHacks;
# and that's all there is to it!

DESCRIPTION

This module replaces several methods in the PPI namespace with custom versions that cache their results to improve performance. There are no user-serviceable parts in here.

DISCUSSION

I used Devel::NYTProf to analyze the performance of perlcritic as it critiqued a large number of files. The results showed that we were spending a lot of time in PPI searching and stringifying parts of the Document. As PPI was originally written each one of these operations is done from scratch, even if it had already been done before. And for a dynamic Document, this is perfectly reasonable. However, Perl::Critic implicitly expects the document to be immutable. Therefore, it was possible to rewrite some of the methods in PPI to use a cache.

When using these cached methods, performance improved by about 30%. However, this measurement can vary significantly, depending on which policies are active (the more Policies you use, the more performance benefit you'll see). Also, certain Policies like RequireTidyCode and PodSpelling are very slow and rely on external code, so they tend to skew performance measurements.

METHODS

flush_caches()

Completely flushes all caches.

IMPLEMENTATION NOTES

I first attempted to use memoize as the caching mechanism. But it caused segmentation faults (probably because I wasn't purging the cache after each document). Rather than fuss with that, I just decided to roll my own caching mechanism. So that's what you see here.

I also shopped around on CPAN for a module that would allow me to replace subroutines without those nasty typeglobs. But I couldn't find one that would also give me a handle to the original subroutine. I'm open to suggestions if you know of a solution here.

TODO

I don't want this kind of module to become a habit. We should talk to Adam Kennedy about possibly extending PPI with a proper PPI::Document::Immutable subclass that has these sorts of caching methods built into it.

AUTHOR

Jeffrey Ryan Thalhammer <thaljef@cpan.org>

COPYRIGHT

Copyright (c) 2009 Jeffrey Ryan Thalhammer. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.