4 ms·
One thing that stands out is that you are basically duplicating the entire file into memory, which might be a problem if your files are bigger than your free RA
by Terr_ 2y ago
One thing that stands out is that you are basically duplicating the entire file into memory, which might be a problem if your files are bigger than your free RAM.
This is because pattern.search(subject) returns a Match object which contains the original line, and you're keeping all of them in the resulting list.
It should be easy to check if that's the issue by monitoring system memory usage, or by testing with a version that does the search but immediately discards the result.