Re: [Parseperl-discuss] Performance hacks
Brought to you by:
adamkennedy
From: Chris D. <ch...@ch...> - 2006-07-20 14:52:25
|
On Jul 20, 2006, at 2:42 AM, Adam Kennedy wrote: >>> my $doc = PPI::Document->new( $something, >>> readonly => 1, >>> ); >> I was thinking something quite similar earlier today, but I >> couldn't think of a good way to implement it without either 1) >> sprinkling "if ($self->top->readonly)" everywhere, or 2) multiple >> inheritance or mixin of a ::Mutable class for the non-readonly case. > > Agreed, actually checking it in every ->prune call would be onerous > and slow things down, and doing some form of mutation or mixin for > non-read-only seems infeasible without having entire seperate > trees, tripling the number of classes. :/ Like you suggested, I'll play with PPI-XS before actually trying to optimize PPI, but this is an interesting topic. How about using caches with epoch number? It might still be too much overhead (especially in $self->top), but here's some noodling: package PPI::Node; sub remove { ... $self->top->inc_epoch; ... } sub inc_epoch { $self->{epoch}++; # maybe delete some caches pre-emptively? } sub epoch { $self->{epoch} || 0; } sub content { my ($self) = @_; my $epoch = $self->top->epoch; $self->{cache} = {epoch => $epoch} if (!$self->{cache} || $self- >{cache}->{epoch} != $epoch); return $self->{cache}->{content} ||= join q{}, map { $_- >content } @{$self->{children}}; } If the lexer can be exempt from caching and the ratio of reads to writes is large (like Perl::Critic), this could be a win, but I'm not sure. Chris -- Chris Dolan, Software Developer, Clotho Advanced Media Inc. 608-294-7900, fax 294-7025, 1435 E Main St, Madison WI 53703 vCard: http://www.chrisdolan.net/ChrisDolan.vcf Clotho Advanced Media, Inc. - Creators of MediaLandscape Software (http://www.media-landscape.com/) and partners in the revolutionary Croquet project (http://www.opencroquet.org/) |