fix(query): overflow in capture pool ids + some perf#5555
Merged
Conversation
Commit 1f6eac5 ("query: Use uint32_t for capture list IDs") widened QueryState.capture_list_id to uint32_t and removed the 65536 pool cap, but left the pool function signatures as uint16_t. This caused silent truncation when the pool exceeded 65535 entries, leading to a segfault. (cherry picked from commit 361f293)
`ts_query_cursor_next_capture` linearly scanned all finished states to find the one with the earliest next capture byte offset. With deeply nested code, this O(n) scan per capture caused the highlight crate to hang for minutes on large files. Replace the linear scan with a min-heap over the finished_states array, keyed by (next_capture_byte_offset, pattern_index, id). The heap is maintained lazily: ts_query_cursor__advance uses plain array_push (preserving FIFO insertion order), and next_capture sifts new elements into the heap on entry via a tracked heap_size boundary. This preserves the documented "order found" guarantee for next_match while giving next_capture O(log n) per call. (cherry picked from commit 123fb1c)
(cherry picked from commit 43dc8ea)
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.
Description
Backport of #5548 to
release-0.26.