gh-152930: Make tomllib parse each table section in linear time#152931
Open
tonghuaroot wants to merge 2 commits into
Open
gh-152930: Make tomllib parse each table section in linear time#152931tonghuaroot wants to merge 2 commits into
tonghuaroot wants to merge 2 commits into
Conversation
key_value_rule re-walked the whole table header from the document root for every key under it, so a deep header followed by many keys parsed in time proportional to depth times keys. Resolve the section's flags and nest node once per header and walk only the key relative to it, making each section linear in depth plus keys.
Member
|
This should be first handled in https://github.com/hukkin/tomli. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolve each table section's flags and nest node once when its
[header]line is parsed, and have
key_value_rulewalk only the key relative to thatanchor instead of re-walking
header + keyfrom the document root for everykey. A section with a depth
Dheader andMkeys goes fromO(M * D)toO(M + D).Parse results are unchanged: the fix produces identical output against the
full toml-test 1.0.0 corpus and the existing
test_tomllibsuite, andD=998, M=80000(714 KB) drops from about 11.7 s to about 0.18 s.