-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Improve tomllib startup time #147991
Copy link
Copy link
Open
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory