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 of `tomllib` by hukkin · Pull Request #128907 · python/cpython

Conversation

@hukkin

@hukkin hukkin commented Jan 16, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This is a port of two commits in Tomli repository (the diff of these commits being hukkin/tomli@42a570d...1da01ef).

This removes runtime overhead of string, typing, and tomllib._types imports from import tomllib.

main branch

$ hyperfine --warmup 8 "./python -c 'import tomllib'" "./python -c 'pass'"
Benchmark 1: ./python -c 'import tomllib'
  Time (mean ± σ):      70.3 ms ±   1.8 ms    [User: 66.0 ms, System: 4.3 ms]
  Range (min … max):    68.6 ms …  76.8 ms    41 runs
 
Benchmark 2: ./python -c 'pass'
  Time (mean ± σ):      26.2 ms ±   0.7 ms    [User: 23.3 ms, System: 3.0 ms]
  Range (min … max):    25.1 ms …  29.7 ms    110 runs
 
Summary
  './python -c 'pass'' ran
    2.69 ± 0.10 times faster than './python -c 'import tomllib''

PR branch

$ hyperfine --warmup 8 "./python -c 'import tomllib'" "./python -c 'pass'"
Benchmark 1: ./python -c 'import tomllib'
  Time (mean ± σ):      48.0 ms ±   0.7 ms    [User: 43.4 ms, System: 4.7 ms]
  Range (min … max):    46.8 ms …  50.2 ms    60 runs
 
Benchmark 2: ./python -c 'pass'
  Time (mean ± σ):      26.1 ms ±   0.4 ms    [User: 23.5 ms, System: 2.7 ms]
  Range (min … max):    25.3 ms …  27.4 ms    110 runs
 
Summary
  './python -c 'pass'' ran
    1.84 ± 0.04 times faster than './python -c 'import tomllib''
  • 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.

AA-Turner reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@hukkin
Improve import time of tomllib
9cf12a8
@hukkin
hukkin requested review from encukou and hauntsaninja as code owners January 16, 2025 08:49
@bedevere-app bedevere-app Bot mentioned this pull request Jan 16, 2025
Improve import time of various stdlib modules #118761
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Jan 16, 2025
AA-Turner
AA-Turner reviewed Jan 16, 2025
View reviewed changes
Comment thread Lib/tomllib/_parser.py Resolved

Uh oh!

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

Comment thread Lib/tomllib/_parser.py Resolved

Uh oh!

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

@vstinner

vstinner commented Jan 16, 2025

Copy link
Copy Markdown
Member

cc @encukou who added the module in Python 3.11 (PEP 680).

All reactions

Sorry, something went wrong.

Uh oh!

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

AA-Turner
AA-Turner approved these changes Jan 16, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jan 16, 2025
hauntsaninja
hauntsaninja approved these changes Jan 16, 2025
View reviewed changes
gpshead
gpshead approved these changes Jan 17, 2025
View reviewed changes
@gpshead
gpshead merged commit ea6cc26 into python:main Jan 17, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 17, 2025
@hukkin
hukkin deleted the tomllib-importtime branch January 17, 2025 05:47
@encukou

encukou commented Jan 17, 2025

Copy link
Copy Markdown
Member

Thank you!

All reactions

Sorry, something went wrong.

Uh oh!

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

@AA-Turner AA-Turner mentioned this pull request Jan 30, 2025
Improve importlib backports-upstream integration #129307
Open
@AA-Turner AA-Turner mentioned this pull request Apr 29, 2025
Enable type checking of tomllib stdlib folder #133117
Closed
@kdeldycke kdeldycke mentioned this pull request Oct 23, 2025
Defer typing imports csala/mdformat-simple-breaks#5
Merged
@ptweezy ptweezy mentioned this pull request Nov 5, 2026
Speed up import isal.igzip by not importing the typing module pycompression/python-isal#319
Merged
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes
@AA-Turner AA-Turner AA-Turner approved these changes
@hauntsaninja hauntsaninja hauntsaninja approved these changes
@encukou encukou Awaiting requested review from encukou encukou is a code owner

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.

6 participants

@hukkin @vstinner @encukou @gpshead @AA-Turner @hauntsaninja
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.