in reply to Re^2: RE on lines read from in-memory scalar is very slow
in thread RE on lines read from in-memory scalar is very slow
The problem with what I think you're suggesting is readline/sv_gets() doesn't know about the SV behind a file handle created from a reference, it's just another file - one where the buffer isn't the normal size.
As to the modifications to the SV the file handle refers to, making such a file handle doesn't copy the SV - changes to the SV are reflected in the values returned by reads from the handle, and writes to the handle are (obviously) reflected when reading from the SV. (changes to the SV have led to some bugs).
Note that in the match case, on success perl makes a CoW copy of the whole matched SV, and the magic for $1, $& etc copies the appropriate text from from that CoW SV. That CoW copy is part of the problem here.
As to the multiple 16M allocations, that's the other part of the bug here, sv_gets() is preallocating the target SV to way too large a size.
For your performance issue, you could post here (on perlmonks, not necessarily this thread) with the code and performance numbers for discussion and/or make a ticket against perl itself on github. The main issue I can think of comparing readline() vs split is readline goes through more layers (pp_readline, sv_gets, PerlIO, PerlIO::scalar vs pp_split, regexp) which is going to slow things down. A test case can be investigated with a profiler (gprof, perf record, valgrind callgrind, cygwin profiler, visual studio profiler) to see if something is consuming more than the expected CPU time.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: RE on lines read from in-memory scalar is very slow
by NERDVANA (Priest) on Feb 20, 2024 at 23:43 UTC | |
by tonyc (Hermit) on Feb 21, 2024 at 00:01 UTC | |
by NERDVANA (Priest) on Feb 21, 2024 at 00:10 UTC |