Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Substitution unexpectedly very slow, in Strawberry

by swl (Parson)
on Aug 06, 2023 at 22:21 UTC ( #11153749=note: print w/replies, xml ) Need Help??


in reply to Substitution unexpectedly very slow, in Strawberry

Still occurs with Strawberry Perl 5.36.1 and 5.38.0 (see below) although I suspect it is more generic than Strawberry Perl.

Running the code through nytprof shows 1000001 calls to main::CORE:substcont at line 10 take most of the time.

It does not happen when the $x repetition is set to 1e5. There was a possibly related thread here a few months ago about character repetitions and COW but I can't locate it right now.

0.224835157394409 0.228233814239502 v5.22.3 9.92650699615479 0.662662982940674 v5.28.0 8.49285101890564 0.744230985641479 v5.36.1 8.02936911582947 0.788676977157593 v5.38.0

Replies are listed 'Best First'.
Re^2: Substitution unexpectedly very slow, in Strawberry
by syphilis (Archbishop) on Aug 07, 2023 at 02:13 UTC
    There was a possibly related thread here a few months ago about character repetitions and COW but I can't locate it right now.

    It would be interesting to compare with a perl that was built without the COW.
    How might that be achieved on Windows ? (In fact, how is it even done on Linux ? IIRC it's fairly easily do-able on *nix but I can't find the relevant documentation.)

    On Windows, I'm seeing the same thing, irrespective of whether perl-5.38.0 is built with a mingw-w64 port of gcc or with Microsoft's Visual Studio 2022. Unthreaded builds of perl fare just as poorly as the multi-thread builds.
    The one thing that does make a big difference is to use a 32-bit build of perl.
    For example, with a 64-bit MSVC-built perl-5.38.0:
    >perl time.pl 6.13913488388062 0.530965089797974 v5.38.0
    For a 32-bit perl-5.38.0 built using the same MSVC compiler (VS2022) in 32-bit mode:
    >perl time.pl 0.0664510726928711 0.0533270835876465 v5.38.0
    But even with that 32-bit build of perl, the same issue becomes evident when "1e6" is changed to "2e6":
    >perl time.pl 6.67774796485901 1.07769107818604 v5.38.0
    Cheers,
    Rob

      It also might not be related to COW and instead be something in the regex engine that is specific to windows. It's probably worth flagging with p5p.

        It also might not be related to COW and instead be something in the regex engine that is specific to windows.

        I wouldn't yet assume that it doesn't afflict Linux.
        Sure, there's nothing much in the figures that hippo choroba posted earlier, but I wonder if the same thing might become evident on Linux if "1e6" is increased to "2e6" or beyond.

        It's probably worth flagging with p5p

        Probably, yes.
        The 5.38.0 perlvar docs still warn about the potential performance hits of using $&, but then they also say (regarding $`, $& and $')
        In Perl 5.20.0 a new copy-on-write system was enabled by default, +which finally fixes most of the performance issues with these three vari +ables, and makes them safe to use anywhere.
        But note that it says "most of the performance issues".
        And I'm still a bit curious to know whether a perl-5.38.0 windows perl built without COW would suffer the same slowdown.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11153749]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2023-12-01 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?