Re: findvalue is very slow

Petr Pajas <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On pá 23. května 2008, Vincent Lefevre wrote:
> Hi,
>
> Is there any reason why findvalue is very slow?

(In XML::LibXML, that is)

At least two factors make your findvalue test much slower than the 
others: 1st it employs the whole XPath machinery (creating context, 
parsing the XPath expression, evaulating the XPath expression) 
rather than simply askin for a struct value like the others, 2nd 
looking at the implementation one discoveres that findvalue 
involves several Perl subroutine calls, including creating an 
object and then serializing it back. Surely, there is quite some 
space for optimizing it ( patches that optimize but do not alter 
the behavior are welcome).

sub findvalue {
   my ($node, $xpath) = @_;
    my $res;
    eval {
        $res = $node->find($xpath);
    };
    if  ( $@ ) {
        die $@;
    }
    return $res->to_literal->value;
}

sub find {
    my ($node, $xpath) = @_;
    my ($type, @params) = $node->_find($xpath);
    if ($type) {
        return $type->new(@params);
    }
    return undef;
}

-- Petr
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.