GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-118761: Improve import time for `csv` by picnixz · Pull Request #128858 · python/cpython

Conversation

@picnixz

@picnixz picnixz commented Jan 15, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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
  • Issue: Improve import time of various stdlib modules #118761

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

danielhollas and hugovk reacted with rocket emoji
All reactions
  • 🚀 2 reactions
picnixz added 2 commits January 15, 2025 09:49
@picnixz
Improve import time of csv.
348f2f7
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`.
@picnixz
blurb
fb7ede3
@bedevere-app bedevere-app Bot mentioned this pull request Jan 15, 2025
Improve import time of various stdlib modules #118761
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Jan 15, 2025
@picnixz
picnixz requested review from AA-Turner, hugovk and vstinner January 15, 2025 08:55
vstinner
vstinner approved these changes Jan 15, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jan 15, 2025
@picnixz

picnixz commented Jan 15, 2025

Copy link
Copy Markdown
Member Author

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).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk
hugovk approved these changes Jan 15, 2025
View reviewed changes

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

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.

Looks good, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
AA-Turner
AA-Turner approved these changes Jan 16, 2025
View reviewed changes
@picnixz picnixz mentioned this pull request Jan 17, 2025
gh-118761: Reduce import time of gettext.py by delaying re import #128898
Merged
@picnixz
picnixz merged commit d5e9aa6 into python:main Jan 18, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 18, 2025
@picnixz
picnixz deleted the perf/import/csv-118761 branch January 18, 2025 10:45
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 21, 2025
@picnixz @srinivasreddy
pythongh-118761: Improve import time for csv (python#128858)
92c9ffb
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@hugovk hugovk hugovk approved these changes
@AA-Turner AA-Turner AA-Turner approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

4 participants

@picnixz @vstinner @hugovk @AA-Turner
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.