Conversation
Make tomli import time up to 10x faster on Python 3.15. Use Python 3.15 lazy imports to only load regular expressions to parse datetime, localtime or non-trivial numbers (others than just decimal digits). Add try_simple_decimal() parser for simple decimal numbers. On Python 3.15, use also the new built-in frozendict type (for BASIC_STR_ESCAPE_REPLACEMENTS), instead of types.MappingProxyType.
for more information, see https://pre-commit.ci
|
Hi! I adapted my change for Python tomllib to tomli. I replaced |
|
"Tests / Binary wheels for macOS (pull_request)" failed with: "Tests / coverage (pull_request)" failed because |
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #292 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 535 558 +23
Branches 100 106 +6
=========================================
+ Hits 535 558 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi! With what I currently know, I wouldn't merge the
If CPython codeowners consider this optimization more important than what it currently appears to me, I'll merge anyway just to keep the tomli/tomllib diff down. Let me know @encukou @hauntsaninja! |
for more information, see https://pre-commit.ci
I understand that. It's your call to decide if the startup time optimization is worth it.
I consider that improving startup time is worth it even if the PEP is rejected, so I proposed this change.
I made a tiny change (add I pushed a change adding I wrote a benchmark using import pyperf
import os.path
import tomli
with open('pyproject.toml', 'rb') as fp:
PYPROJECT_TOML = fp.read().decode()
with open('benchmark/data.toml', 'rb') as fp:
BENCHMARK_TOML = fp.read().decode()
def parse_toml(data):
tomli.loads(data)
runner = pyperf.Runner()
runner.bench_func(f'parse benchmark/data.toml', parse_toml, BENCHMARK_TOML)
runner.bench_func(f'parse pyproject.toml', parse_toml, PYPROJECT_TOML)Results on my Fedora 43 laptop with CPU isolation: So this change has no significant impact on performance.
Note: |
|
I agree that the speedup doesn't look like it's worth the implementation complexity, especially before PEP 829 is accepted. |
|
I extracted the |
|
Would you like to extract the lazy import change in a separate PR too? Integers seem rarely used in TOML so I think it makes sense even without |
|
Ok, I abandon this change and I wrote #295 to only add |
Make tomli import time up to 10x faster on Python 3.15. Use Python 3.15 lazy imports to only load regular expressions to parse datetime, localtime or non-trivial numbers (others than just decimal digits). Add try_simple_decimal() parser for simple decimal numbers.
On Python 3.15, use also the new built-in frozendict type (for BASIC_STR_ESCAPE_REPLACEMENTS), instead of types.MappingProxyType.