gh-106628: email parsing speedup#106629
Merged
corona10 merged 2 commits intopython:mainfrom Jul 13, 2023
Merged
Conversation
Don't compile a new regular expression for every single email that is being parsed. Instead, use str.startswith and a generic regular expression.
corona10
approved these changes
Jul 11, 2023
Member
corona10
left a comment
There was a problem hiding this comment.
lgtm
baseline
Number of emails in the mbox file: 10000 filesize: 246081876
[1000] avg 0.434 msec/email (total time: 0.44 seconds)
[2000] avg 0.350 msec/email (total time: 0.79 seconds)
[3000] avg 0.368 msec/email (total time: 1.15 seconds)
[4000] avg 0.462 msec/email (total time: 1.62 seconds)
[5000] avg 0.375 msec/email (total time: 1.99 seconds)
[6000] avg 0.412 msec/email (total time: 2.40 seconds)
[7000] avg 0.374 msec/email (total time: 2.78 seconds)
[8000] avg 0.405 msec/email (total time: 3.18 seconds)
[9000] avg 0.383 msec/email (total time: 3.56 seconds)
PR
Number of emails in the mbox file: 10000 filesize: 246081876
[1000] avg 0.398 msec/email (total time: 0.40 seconds)
[2000] avg 0.309 msec/email (total time: 0.71 seconds)
[3000] avg 0.329 msec/email (total time: 1.04 seconds)
[4000] avg 0.435 msec/email (total time: 1.48 seconds)
[5000] avg 0.336 msec/email (total time: 1.81 seconds)
[6000] avg 0.385 msec/email (total time: 2.20 seconds)
[7000] avg 0.326 msec/email (total time: 2.52 seconds)
[8000] avg 0.350 msec/email (total time: 2.87 seconds)
[9000] avg 0.321 msec/email (total time: 3.19 seconds)
Member
|
I will merge this PR if there is no major objection in this week :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As described in #106628, this PR speeds up email parsing by not compiling a regular expression for every single email parsed. On the benchmark that the original bug reporter submitted to us, this gives a 20% speedup when parsing the 235MiB example mbox file containing 10,000 emails on CPython main (on PyPy the speedup is massively larger even, but only because the previous performance was extra bad).