Skip Menu |
 

This queue is for tickets about the XML-XPath CPAN distribution.

Report information
The Basics
Id: 23924
Status: resolved
Priority: 0/
Queue: XML-XPath

People
Owner: MANWAR [...] cpan.org
Requestors: bitcard [...] kindlund.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.13
Fixed in: 1.19



Subject: Regex Slowdown: XPath.pm:195 Uses ($`)
Download (untitled) / with headers
text/plain 1.3k
On line 195 in XML::XPath within the setNodeText() function: my $parent_path = $`; This one line causes the ENTIRE perl regular expression engine to slow down dramatically. Furthermore, any libraries that simply "use XML::XPath" experience this same slowdown -- even if the the setNodeText() function is never called. This slowdown is due to the native Perl interpreter -- as stated in "perldoc perlre": WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to pro- duce $1, $2, etc, so you also pay a price for each pattern that con- tains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the extended regular expression "(?: ... )" instead.) But if you never use $&, $` or $', then patterns without capturing parentheses will not be penalized. So avoid $&, $', and $` if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid the price. As of 5.005, $& is not so costly as the other two. If there is ANY way to alter line 195 such that $&, $`, and $' are never used, then XPath and all subsequent dependencies will obtain a huge performance boost (within the regular expression engine).
From: bitcard [...] kindlund.com
Download (untitled) / with headers
text/plain 404b
Based upon the 'perlvar' documentation located at: http://perldoc.perl.org/perlvar.html The @LAST_MATCH_START section indicates that there's a more efficient version of $` that can be used. Specifically, after a match against some variable $var: * $` is the same as substr($var, 0, $-[0]) This patch reflects this one-line change. 'make test' successfully ran on v1.13 after applying this patch.
Download xpath-23934.patch
text/x-diff 456b
--- XPath.pm-bak 2006-12-14 03:30:41.908004600 -0500 +++ XPath.pm 2006-12-14 03:30:41.887975000 -0500 @@ -192,7 +192,7 @@ if ($#nodes < 0) { if ($node_path =~ m|/@([^/]+)$|) { # attribute not found, so try to create it - my $parent_path = $`; + my $parent_path = substr($node_path, 0, $-[0]); my $attr = $1; $nodeset = $self->findnodes($parent_path); return undef if (!defined $nodeset); # could not find node
Hi, Thanks for reporting the issue, I will get it patched asap. Best Regards, Mohammad S Anwar
Resolved.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.