Repository navigation
Refactor file content searching for a 40% speed increase - #2505
Conversation
|
This is amazing!! I'll look into merging this today |
|
This is a really amazing refactoring, thanks so much for this! Love the use of the lazy Should probably go further and try to put |
Before you do that, I have another PR in the waiting that depends on this PR and makes the file searching another 20% faster. I will open it as soon as this is merged. |
vladsavelyev
left a comment
There was a problem hiding this comment.
Looks great! Thanks a lot for the clear and very pythonic code. Very excited for future optimizations.
By the way, feel free to create stacked PRs if if you have more cool stuff downstream of an existing unmergeed PR - i.e. when pr_a is based from main, pr_b is based from pr_a, etc. Even if it's a draft. Good to anticipate more awesome stuff so I don't accidentally create unnecessary merge conflicts 👍
This report does the following:
The previous code would reuse the content lines as much as possible, but would read the file again when not enough content lines were read already. By using a object, the existing filehandle can be kept alive. This prevents reopening and rereading.
Also by moving all the line reading code into a separate function, the resulting code in
search_filehas become more readable in my opinion.The speed uplift is very significant. Tested with
multiqc --force --no-data-dir --profile-runtime ../test-data/(The multiqc test-data repo)Before:
After:
A more than 40% reduction in searching files is very welcome. This was benchmarked on a nvme SSD, but I regularly work in a Network Filesystem which is orders of magnitude slower. These speed increases become very significant in such environments.