-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed as not planned
Closed as not planned
Copy link
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
The email.header.decode_header function does multiple calls to parts.pop(0) in a loop, where parts is a list. This is slow, because it has to shift the rest of the elements every time.
I have locally changed code where I stop doing pop(0), and instead operate on list index, which avoids the issue.
This is what pyperf says (the test string is copied from unit tests):
$ python -m pyperf timeit 'from email.header import decode_header;decode_header("=?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]>")' -o email_decode_header_baseline.json
# apply optimization
$ python -m pyperf timeit 'from email.header import decode_header;decode_header("=?ISO-8859-1?Q?Andr=E9?= Pirard <[email protected]>")' -o email_decode_header_optimized.json
$ python -m pyperf compare_to email_decode_header_baseline.json email_decode_header_optimized.json
Mean +- std dev: [email_decode_header_baseline] 6.21 us +- 0.05 us -> [email_decode_header_optimized] 6.11 us +- 0.06 us: 1.02x faster
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancementA feature request or enhancement