Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve tomllib startup time #147991

Description

@vstinner

Currently, importing tomllib takes 9.5 ms. I wrote a proof-of-concept which defers importing regular expressions: with this change, importing tomllib now only takes 0.9 ms (10.6x faster).

Benchmark on Python built in release mode (gcc -O3) on Fedora 43:

$ python -m pyperf command -- ./python -S -c 'pass'
command: Mean +- std dev: 7.77 ms +- 0.75 ms
$ python -m pyperf command -- ./python -S -c 'import tomllib'
command: Mean +- std dev: 17.3 ms +- 0.3 ms

With my change:

$ python -m pyperf command -- ./python -S -c 'import tomllib'
command: Mean +- std dev: 8.70 ms +- 0.82 ms

This optimization is motivated by PEP 829: Structured Startup Configuration via .site.toml Files discussion which proposes using tomllib at Python startup.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions