Stop re-deciding what the index already decided - #79
Merged
Conversation
A query picks the index that suits its filter, walks it, and then checks each candidate against the whole filter again. Two of those checks cannot fail. Reaching an event through its author's index proves the author matches; reading it because its id was named proves the id does. `Filter.matches` compares against a list one entry at a time, so the redundant half is a scan of the whole list, per candidate. A feed over a real follow list re-scanned two thousand pubkeys for every note it returned, having reached that note through the very index that answered the question. A client refreshing a feed it already holds by naming the ids it holds pays it squared. Each branch now nulls out what its index guaranteed and checks the rest. Time bounds stay in: they cost nothing and they are a check on the index agreeing with the record it points at. `QueryResult.list_checks` reports the size of that term, the same way `examined` reports index entries read. It is zero for every filter an index can answer, which is the property the new tests assert. A stopwatch cannot tell a quadratic scan from a busy machine; this can. Measured on this machine, ReleaseFast, best of 50 and the lowest of repeated runs, 2049 authors over 210k events: same feed by id, 1200 ids : 1202 us -> 871 us (list_checks 3.9M -> 0) same feed by id, 300 ids : 260 us -> 231 us same feed by id, 60 ids : 61 us -> 56 us wide feed, limit 60 : no measurable change The merged path's saving is real but small at that shape: its cost is the cursor per author and the linear pick across streams, not this. The win is on the by-id path, and it grows with how many ids are named.
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.
A query picks the index that suits its filter, walks it, and then checks each candidate against the whole filter again. Two of those checks cannot fail. Reaching an event through its author's index proves the author matches; reading it because its id was named proves the id does.
Filter.matchescompares against a list one entry at a time, so the redundant half is a scan of the whole list, per candidate. A feed over a real follow list re-scanned two thousand pubkeys for every note it returned, having reached that note through the very index that answered the question. A client refreshing a feed it already holds by naming the ids it holds pays it squared.Each branch now nulls out what its index guaranteed and checks the rest. Time bounds stay in: they cost nothing, and they are a check on the index agreeing with the record it points at.
The number
QueryResult.list_checksreports the size of that term, the wayexaminedalready reports index entries read. It is zero for every filter an index can answer, which is the property the new tests assert. A stopwatch cannot tell a quadratic scan from a busy machine; this can.ReleaseFast, best of 50 and the lowest of repeated runs, 2049 authors over 210k events:
list_checksThe merged path's saving is real but small at that shape, and I am not going to claim otherwise: its cost is the cursor per author and the linear pick across streams, not this. The win is on the by-id path and it grows with how many ids are named.
Tests
Four, and all four fail without the change, with the counts you would predict:
list_checks6000 to 0list_checks40000 to 0Verified by putting the old behaviour back and watching each one go red.