Repository navigation
Avoid quadratic anchor lookup in large documents - #363
Open
adenzhou1350 wants to merge 1 commit into
Open
adenzhou1350 wants to merge 1 commit into
adenzhou1350 wants to merge 1 commit into
Conversation
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.
yaml_parser_register_anchor()andyaml_parser_load_alias()repeatedly scan the aliases vector, making documents with many anchors expensive to compose. This keeps the existing linear path through 64 anchors and builds a document-local AVL index when the 65th anchor is registered.The private index stores integer offsets into the aliases vector, so vector reallocations do not invalidate it. It is freed on both document success and failure. Public headers, parser layouts and ABI are unchanged; duplicate-anchor marks, undefined-alias errors, cycles and document-local reset retain their existing behavior.
Fixes #359.
Validation on Linux/GCC 12.2:
-O3 -DNDEBUG): all four registered tests pass. The new test restores assertions and checks 74 public-API cases, including sorted/reverse/shuffled names, the 64/65 transition, growth boundaries, exact reference identities and indexed error/reset paths. The same 74 cases pass against the original library.-O2libraries, 14 cases, 112 fresh processes per observation). At 16,000 anchors, the median B/C ratios are about 42x without aliases and 83x with repeated references to the last anchor. These stress linear lookup and are not application-throughput claims. Small cases have tradeoffs: first-run empty/ordinary/small medians range from 0.963x to 1.038x, including about 3.7% slowdown at eight references. Four pairs on one shared host give limited precision.Portable reproducer, both complete observations and limitations are on a separate fork branch, outside this PR's four-file diff. The portable runner itself was executed successfully against both exact native archives.
Autotools registration is included, but local
make test-all, the external YAML test-suite corpus, other platforms and hosted CI remain unverified. Development was AI-assisted.