tall_man has asked for the wisdom of the Perl Monks concerning the following question:

I have noticed a problem when trying to debug programs that use XML::Simple::XMLin. The program runs very quickly with regular perl, but with "perl -d" or "perl -d:ptkdb" the XMLin line is very slow, taking about 30 seconds even on simple input.

When I interrupt the call under "perl -d", I am always somewhere in utf8_heavy.pl.

tf8::SWASHNEW(/opt/acs/perl/lib/perl5/5.8.0/utf8_heavy.pl:167): 167: my $val = hex(defined $3 ? $3 : "");
Also, I get the following message when using -d:ptkdb, at exit time:
DESTROY created new reference to dead object 'utf8' during global dest +ruction.
Does anyone know of interactions between utf8 and the debugger that would cause slowdowns and reference problems? I am using perl 5.8.0. I have seen the same problem under Linux and Windows NT.

Here is some sample code to reproduce the problem:

use strict; use XML::Simple; my $data; { local $/; $data = <DATA>; } my $config = XMLin($data); print "config read\n"; __DATA__ <config logdir="/var/log/foo/" debugfile="/tmp/foo.debug"> <server name="sahara" osname="solaris" osversion="2.6"> <address>10.0.0.101</address> <address>10.0.1.101</address> </server> <server name="gobi" osname="irix" osversion="6.5"> <address>10.0.0.102</address> </server> <server name="kalahari" osname="linux" osversion="2.0.34"> <address>10.0.0.103</address> <address>10.0.1.103</address> </server> </config>

Replies are listed 'Best First'.
Re: XMLin slow in debug mode?
by BrowserUk (Patriarch) on Jul 09, 2003 at 17:23 UTC

    I can't reproduce the slowdown you report. Adding a little crude timing code to your script

    my $start = times; my $config = XMLin($data); my $stop = times; print "$start:$stop: ",$stop - $start; print "config read\n";

    It seems to show that it takes just over twice as long to run under the debugger as not

    P:\test>junk 0.39:1.381: 0.991 config read P:\test>perl -d junk.pl8 Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(junk.pl8:5): my $data; main::(junk.pl8:6): { DB<1> c 14 1.792:3.945: 2.153 main::(junk.pl8:14): print "config read\n"; DB<2>

    which seems reasonable and nowhere near the 30 seconds you are seeing.

    Perhaps you have some PERL5DB_OPTS set that could account for it?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


      I don't have any extra PERL5DB_OPTS set. It may be a difference in the XML::Simple configuration I'm using. Here's part of a stack trace during the slowdown:
      = utf8::SWASHNEW('utf8', '', '# comment^J0100^I0131^J0134^I013e^J0141 +^I0148^J', 1, 0) called from file `/opt/acs/perl/lib/perl5/site_perl/ +5.8.0/XML/SAX/PurePerl/Reader.pm' line 115 $ = XML::SAX::PurePerl::Reader::match_re(ref(XML::SAX::PurePerl::Reade +r::String), ref(Regexp)) called from file `/opt/acs/perl/lib/perl5/si +te_perl/5.8.0/XML/SAX/PurePerl/Reader.pm' line 256 . = XML::SAX::PurePerl::Reader::consume(ref(XML::SAX::PurePerl::Reader +::String), ref(Regexp)) called from file `/opt/acs/perl/lib/perl5/sit +e_perl/5.8.0/XML/SAX/PurePerl/Reader.pm' line 246 $ = XML::SAX::PurePerl::Reader::consume_name(ref(XML::SAX::PurePerl::R +eader::String)) called from file `/opt/acs/perl/lib/perl5/site_perl/5 +.8.0/XML/SAX/PurePerl.pm' line 677 $ = XML::SAX::PurePerl::Name(ref(XML::SAX::PurePerl), ref(XML::SAX::Pu +rePerl::Reader::String)) called from file `/opt/acs/perl/lib/perl5/si +te_perl/5.8.0/XML/SAX/PurePerl.pm' line 555 @ = XML::SAX::PurePerl::Attribute(ref(XML::SAX::PurePerl), ref(XML::SA +X::PurePerl::Reader::String)) called from file `/opt/acs/perl/lib/per +l5/site_perl/5.8.0/XML/SAX/PurePerl.pm' line 163 $ = XML::SAX::PurePerl::element(ref(XML::SAX::PurePerl), ref(XML::SAX: +:PurePerl::Reader::String)) called from file `/opt/acs/perl/lib/perl5 +/site_perl/5.8.0/XML/SAX/PurePerl.pm' line 269 . = XML::SAX::PurePerl::content(ref(XML::SAX::PurePerl), ref(XML::SAX: +:PurePerl::Reader::String)) called from file `/opt/acs/perl/lib/perl5 +/site_perl/5.8.0/XML/SAX/PurePerl.pm' line 239 $ = XML::SAX::PurePerl::element(ref(XML::SAX::PurePerl), ref(XML::SAX: +:PurePerl::Reader::String)) called from file `/opt/acs/perl/lib/perl5 +/site_perl/5.8.0/XML/SAX/PurePerl.pm' line 130 . = XML::SAX::PurePerl::document(ref(XML::SAX::PurePerl), ref(XML::SAX +::PurePerl::Reader::String)) called from file `/opt/acs/perl/lib/perl +5/site_perl/5.8.0/XML/SAX/PurePerl.pm' line 102 $ = XML::SAX::PurePerl::_parse(ref(XML::SAX::PurePerl), ref(XML::SAX:: +PurePerl::Reader::String)) called from file `/opt/acs/perl/lib/perl5/ +site_perl/5.8.0/XML/SAX/PurePerl.pm' line 64 $ = XML::SAX::PurePerl::_parse_string(ref(XML::SAX::PurePerl), '<confi +g ....>') ... called from file `/opt/acs/perl/lib/perl5/site_perl/5.8 +.0/XML/SAX/Base.pm' line 2302
      Would it be slow because I'm using XML::SAX::PurePerl?

      Update: I just installed XML::SAX::Expat, and now the line executes quickly. Thanks for your help, everyone.

        That seems like a strong possibility. When you use one of the C-library versions of XML::Parser, once you enter the library calls, the debugger wouldn't do much until you exit again. With the pure perl version, the debugger is probably interceding at each level of function call, if not every line.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Re: XMLin slow in debug mode?
by flounder99 (Friar) on Jul 09, 2003 at 16:35 UTC
    I cut-n-pasted your code and ran it under Win2k/ActivePerl 806 using -d and hitting "n" a few times. The XMLin line returns immediately. I tried -d:ptkdb and got the same result. I looked at $config in the inspector window and it looks like it parsed the data OK. Sorry I couldn't be more helpful.

    --

    flounder

Re: XMLin slow in debug mode?
by grantm (Parson) on Jul 10, 2003 at 09:51 UTC
    I've found XML::Simple using XML::SAX::PurePerl to be noticeably slow even without the debugger - particularly when running 'make test'. As BrowserUK pointed out, the effect you're seeing is likely due to the fact that it is pure Perl and the debugger has a lot more work to do than if you used a C parser.