Sample Header Ad - 728x90

Why does `less` consume so much CPU with a reasonably sized file, fast disk and plenty of memory?

1 vote
0 answers
89 views
There seems to be a pathological case with one of the files I'm reading with less. The file is ~300MB in size, disk is fast (local NMVE) and the file can comfortably fit in memory, there is no swapping or anything like that. less --version gives me
less 563 (PCRE regular expressions)
on Arch Linux. I run with no commandline parameters (no -R or -S). The file I am reading is being written to. **Usage:** I notice using follow (pressing F) is generally slow for this file, but workable. Things are made worse by having a search active (for highlighting) while follow is in progress. Now if I search for the following: (something|something-else).*|.*warn and then hit F (follow), it totally grinds to a halt. I need to kill it from a different terminal. I've been using such regexes with much larger files with no issue. Could something be amiss? **Edit**: more exact steps and info: - happens with 50MB file, no long lines - another process appends to the file every 15s Steps: - I open the file, go to end (Shift+g) - search for (something|something-else).*|.*warn (says Pattern not found since at the end) - follow (Shift+f) -> CPU goes to 100% and seemingly never stops - instead of pressing Shift+f, the same happens if I press UpArrow following the search - if I reduce the regex to one of its parts (either (something|something-else).* or .*warn the operations take a few seconds, still slow but manageable - resident memory shows as 400MB in htop - **Ctrl+C doesn't work to interrupt it, need to kill from outside**
Asked by haelix (592 rep)
Mar 14, 2021, 12:14 PM
Last activity: Mar 17, 2021, 10:56 AM