GeezerVison is showing github.com — gh-118761: Improve import time for `csv` by picnixz · Pull Request #128858 · python/cpython
Conversation
picnixz
commented
Jan 15, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Benchmarks are for a release non-PGO build (PR) against a PGO build (main). This will be the last PR for that issue.
Note Considering that csv is used in many applications, I think this improvement makes sense (especially for data scientists).
PR
$ ./python -X importtime -c 'import csv'
import time: self [us] | cumulative | imported package
...
import time: 229 | 229 | linecache
import time: 331 | 331 | types
import time: 175 | 175 | _csv
import time: 629 | 1134 | csv
$ hyperfine --warmup 8 "./python -c 'import csv'"
Benchmark 1: ./python -c 'import csv'
Time (mean ± σ): 5.9 ms ± 0.4 ms [User: 5.0 ms, System: 1.0 ms]
Range (min … max): 5.5 ms … 11.0 ms 452 runs
Main
$ ./python -X importtime -c 'import csv'
import time: self [us] | cumulative | imported package
...
import time: 227 | 227 | linecache
import time: 261 | 261 | types
import time: 1419 | 1680 | enum
import time: 62 | 62 | _sre
import time: 218 | 218 | re._constants
import time: 327 | 544 | re._parser
import time: 79 | 79 | re._casefix
import time: 287 | 971 | re._compiler
import time: 90 | 90 | itertools
import time: 86 | 86 | keyword
import time: 46 | 46 | _operator
import time: 187 | 233 | operator
import time: 119 | 119 | reprlib
import time: 45 | 45 | _collections
import time: 733 | 1304 | collections
import time: 39 | 39 | _functools
import time: 498 | 1840 | functools
import time: 114 | 114 | copyreg
import time: 426 | 5029 | re
import time: 107 | 107 | _csv
import time: 575 | 5709 | csv
$ hyperfine --warmup 8 "./python -c 'import csv'"
Benchmark 1: ./python -c 'import csv'
Time (mean ± σ): 9.2 ms ± 0.9 ms [User: 8.0 ms, System: 1.2 ms]
Range (min … max): 8.4 ms … 16.7 ms 297 runs
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
danielhollas and hugovk reacted with rocket emoji
This reduces the import time of the `csv` module
by up to five times, by importing `re` on demand.
In particular, the `re` module is no more implicitly
exposed as `csv.re`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
In a few hours, I will leave until Friday, but I'd like Adam or Hugo to review my English. Feel free to merge this PR and freely update it (otherwise, I'll do it once I'm back).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
srinivasreddy
pushed a commit
to srinivasreddy/cpython
that referenced
this pull request
Jan 21, 2025
This reduces the import time of the `csv` module by up to five times,
by importing `re` on demand.
In particular, the `re` module is no more implicitly exposed as `csv.re`.
Reviewers
vstinner
vstinner approved these changes
hugovk
hugovk approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|