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
Currently, importing
tomllibtakes 9.5 ms. I wrote a proof-of-concept which defers importing regular expressions: with this change, importingtomllibnow only takes 0.9 ms (10.6x faster).Benchmark on Python built in release mode (
gcc -O3) on Fedora 43:With my change:
This optimization is motivated by PEP 829: Structured Startup Configuration via .site.toml Files discussion which proposes using
tomllibat Python startup.Linked PRs