[wip] kvcoord: improve truncate() and next() #68564
Closed
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.
Touches #68536.
Previously, the way the DistSender invoked truncate(), next(), and
prev() was quadratic: each invocation of these functions required
iterating over the entire list of requests in a batch request, to either
find a start key or to find all requests that intersect with a given
range.
However, we can do better: we can process the batches sequentially and
keep track of which parts of the requests' spans we've "chopped off" and
used already. By doing this, we can skip doing extra work for those
already-used span portions.
The loop in this case will remain quadratic, but it's kind of amortized,
since we reduce the set of things to check on every iteration.
There could be a better way of doing this still (Yahor suggested an
interval tree) but I'm not quite sure, and it's complicated.
Release note: None