Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Just a summary, this hasn't been fixed yet.

There's three things contributing to this problem:

  1. when reading from file, sv_gets(), which is used to implement readline(), preallocates the SV to the size of the file handle's buffer, and for an in-memory file, the in-memory file is the buffer, so 16M in this case.
  2. on a match the regular expression engine makes a copy of the input string, and even in cases where perl normally wouldn't make a copy-on-write copy of the input string it does here
  3. Cygwin is very slow in updating the final byte of the large SV buffer (the PV), which holds the CoW reference count. This may be due to the way VirtualAlloc() is used to implement malloc on Cygwin.
1. means we get that huge allocation for the SV, 2. means we try to make it a CoW SV, and 3 produces the horrible performance. As an incidental effect, 2 making the SV CoW means if you save a copy of the SV:
my @save; while (<$fh>) { /successful (match with captures)/; # mark the SV as CoW push @save, $_; # extend the lifetime of the SV's PV until removed +from @save }

the memory use of the program explodes (my machine with 32G ran out of memory testing this).

I have a WIP fix for 2, but it unfortunately leaks in ASAN tests, so I haven't made a PR for it (it does prevent the performance problem)

In reply to Re: RE on lines read from in-memory scalar is very slow by tonyc
in thread RE on lines read from in-memory scalar is very slow by Danny

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-06-19 00:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.