gh-147991: Speed up tomllib import time#147992
Conversation
Defer regular expressions import until the first datetime, localtime or non-trivial number (other that just decimal digits) is met.
|
It might be interesting to replace |
vstinner
left a comment
There was a problem hiding this comment.
I marked added constants and functions as private by adding _ prefix. I'm not sure if it's needed, all other _parser APIs are "public" (no underscore prefix).
Lib/tomllib/_parser.py
Outdated
| if pos >= end: | ||
| break | ||
| else: | ||
| if src[pos] != "\n": |
There was a problem hiding this comment.
Can this happen? We could just return None and fall back to the original path.
There was a problem hiding this comment.
Yes, in many cases. See the added test_parse_simple_number(). Examples:
- The test is true when parsing
1979-05-27: we cannot parse the date. - The test is false when parsing
1\n(ex:value = 1\n) or23, 24]\n(ex:list = [23, 24]\n)
|
I updated the PR to replace I ran benchmarks on the latest PR using Python built in release mode (
|


Defer regular expressions import until the first datetime, localtime or non-trivial number (other that just decimal digits) is met.