commit-reach: remove get_reachable_subset()#2141
Open
spkrka wants to merge 1 commit into
Open
Conversation
|
There is an issue in commit 538378a:
|
get_reachable_subset() and tips_reachable_from_bases() answer the same question: which to-commits are reachable from any of the from-commits. get_reachable_subset() used a graph traversal with a prio_queue until it finds all targets. tips_reachable_from_bases() uses DFS with a rising generation floor, and should be strictly faster, both due to additional pruning via generation numbers as well as O(1) DFS operations instead of O(log(n)) prio_queue operations. In practice these perform the same, and the main win is the code deduplication. The flag in remote.c changes from 1 (bit 0) to TMP_MARK (bit 4) because tips_reachable_from_bases() uses SEEN (bit 0) internally. TMP_MARK is already used for deduplication earlier in the same function and is cleared before the reachability check. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
538378a to
e327567
Compare
Author
|
/cc @derrickstolee |
https://gitgitgadget.github.io/``` |
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.
commit-reach: remove get_reachable_subset()
I have investigated what core graph algorithms exist and how
they are implemented and found that there is some overlap.
get_reachable_subset() and tips_reachable_from_bases() answer
the same question: which commits in a target set are reachable
from a set of base commits.
This patch converts the two callers of get_reachable_subset()
to use tips_reachable_from_bases() and deletes the now-unused
function.
tips_reachable_from_bases() has a minor algorithmic edge: it sorts
targets by generation and dynamically raises the pruning floor as
targets are found. In practice this makes no measurable difference
where the target set is typically small. Without a commit-graph, both
degrade identically -- all generation numbers are INFINITY, so
neither can prune. The main value is removing ~70 lines of code.
A few design choices I'd appreciate feedback on:
add_missing_tags() converts its sent_tips array to a
commit_list to match the tips_reachable_from_bases() API.
This is O(n) list-node allocations, negligible compared to
the graph walk. An array overload could avoid this, but
didn't seem worth adding for a single call site.
The flag changes from 1 (bit 0) to TMP_MARK (bit 4) because
tips_reachable_from_bases() uses SEEN (bit 0) internally.
TMP_MARK is already used for deduplication earlier in the
same function and is cleared before the reachability block.
I kept this as a single commit since the change is small.
Happy to split into convert-callers + delete-function if
that's preferred.
The test helper and test names are renamed from
get_reachable_subset to tips_reachable_from_bases to match
the function being exercised. test_all_modes already covers
both with and without commit-graph.