Repository navigation
perf: bound attribute scans to exactly the queried attribute (#381) - #382
Merged
Merged
Conversation
get_facts_by_attribute ended its AEVT range at next_string_prefix(attr), which increments the last byte. For attributes ending in 0x7F or 0xBF (e.g. `:丿`, `:ÿ`) that is not valid UTF-8, so the committed scan ran to the end of the AEVT index. It also covered prefix siblings (`:ab` for `:a`). End the range at `attribute + "\0"`, the exact successor, as #380 does for the entity path. Remove the now-unused next_string_prefix. Sparse `:丿` scan (100 of 40.1k facts, checkpointed): 45.4 ms -> 251 µs. Closes #381 Refs #323 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BedF9ZmqVZLkvDwn91fuKy
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
FactStorage::get_facts_by_attributeended its AEVT range atnext_string_prefix(attr), which increments the last byte. For attributes ending in0x7For0xBF(about 1 in 64 non-ASCII characters, e.g.:丿,:ÿ), the result is not valid UTF-8, so the committed scan ran to the end of the whole AEVT index and resolved every later fact before post-filtering. The range also covered prefix siblings (:ab,:a/bfor:a).format!("{attribute}\0"), the exact successor. This is the same pattern perf: narrow bound-entity point queries to the queried attribute (#323 mitigation) #380 uses inget_facts_by_entity_attribute_indexed.Nonebranch.next_string_prefixhad no other callers and is removed.Results are unchanged. The committed post-filter is still there as a guard, and the file format is unchanged.
Measurements
Checkpointed file: 100 facts on
:丿plus 40,000 on the neighbouring:丿xand:乀. Query[:find (count ?e) :where [?e :丿 ?v]], bench profile, mean of 10 runs::丿scanTests
attribute_committed_range_is_bounded_for_any_attribute: a mockCommittedIndexReaderrecords the AEVT bounds. It checks that the scan is bounded for:plain,:丿,:\u{bf}and:a\u{7f}, and that prefix siblings fall outside the range. This test fails onmain.attribute_scan_excludes_prefix_siblings_and_non_ascii_neighbours: runs the pending-index path.tests/point_query_history_test.rs::attribute_scan_exact_for_non_ascii_and_prefix_siblings_file_backed: uses committed and pending facts on a real file and checks the results against the full-scan oracle.Full suite: 1168 passed, 0 failed, 8 ignored.
cargo clippy -D warningsis clean. Test counts are updated in CLAUDE.md, README.md and docs/TEST_COVERAGE.md, and the change is added to the CHANGELOG under Unreleased.Closes #381
Refs #323
🤖 Generated with Claude Code
https://claude.ai/code/session_01BedF9ZmqVZLkvDwn91fuKy