Repository navigation
resource: build sub-graphs from a node's dependents instead of pruning a clone #6642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Dan Gottlieb (dgottlieb)
merged 4 commits into
viamrobotics:main
from
qwertey6:subgraph-by-dependents
Oct 20, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8bbafc0
resource: benchmark sub-graphs and reachability on a robot-sized graph
qwertey6 c3c03a7
resource: build sub-graphs from a node's dependents instead of prunin…
qwertey6 749c542
resource: hard-code sub-graph and reachability test expectations
qwertey6 ad89503
Merge main into subgraph-by-dependents
qwertey6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package resource | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "go.viam.com/test" | ||
|
|
||
| "go.viam.com/rdk/logging" | ||
| ) | ||
|
|
||
| // robotSizedGraph builds a graph shaped like a robot with one remote: the | ||
| // remote and 50 resources on it, plus 60 local resources in three layers | ||
| // (components, services on components and remote resources, and services on | ||
| // services). It returns the graph, the remote's name and a component with a | ||
| // dozen dependents. | ||
| func robotSizedGraph(tb testing.TB) (*Graph, Name, Name) { | ||
| tb.Helper() | ||
| g := NewGraph(logging.NewTestLogger(tb)) | ||
| add := func(name Name, deps ...Name) { | ||
| test.That(tb, g.AddNode(name, &GraphNode{}), test.ShouldBeNil) | ||
| for _, dep := range deps { | ||
| test.That(tb, g.AddChild(name, dep), test.ShouldBeNil) | ||
| } | ||
| } | ||
|
|
||
| remote := NewName(APINamespace("rdk").WithType("component").WithSubtype("remote"), "remote1") | ||
| add(remote) | ||
| remoteRes := make([]Name, 50) | ||
| for i := range remoteRes { | ||
| remoteRes[i] = NewName(apiA, fmt.Sprintf("r%d", i)).PrependRemote(remote.Name) | ||
| add(remoteRes[i], remote) | ||
| } | ||
|
|
||
| components := make([]Name, 20) | ||
| for i := range components { | ||
| components[i] = NewName(apiA, fmt.Sprintf("c%d", i)) | ||
| if i < 5 { | ||
| add(components[i]) | ||
| } else { | ||
| add(components[i], components[i%5]) | ||
| } | ||
| } | ||
| services := make([]Name, 25) | ||
| for i := range services { | ||
| services[i] = NewName(apiA, fmt.Sprintf("s%d", i)) | ||
| deps := []Name{components[i%20], components[(i*7+1)%20], components[(i*13+2)%20]} | ||
| if i%2 == 0 { | ||
| deps = append(deps, remoteRes[i%50], remoteRes[(i*3+1)%50]) | ||
| } | ||
| add(services[i], deps...) | ||
| } | ||
| for i := 0; i < 15; i++ { | ||
| add(NewName(apiA, fmt.Sprintf("h%d", i)), services[i%25], services[(i*7+3)%25], components[(i*11)%20]) | ||
| } | ||
| return g, remote, components[3] | ||
| } | ||
|
|
||
| // The remote refresh marks the remote and the remote resources depending on it | ||
| // reachable on every pass. | ||
| func BenchmarkGraphMarkReachability(b *testing.B) { | ||
| g, remote, _ := robotSizedGraph(b) | ||
| b.ReportAllocs() | ||
| b.ResetTimer() | ||
| for i := 0; i < b.N; i++ { | ||
| if err := g.MarkReachability(remote, true); err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Marking a resource's dependents for update starts from its sub-graph. | ||
| func BenchmarkGraphSubGraphFrom(b *testing.B) { | ||
| g, _, component := robotSizedGraph(b) | ||
| b.ReportAllocs() | ||
| b.ResetTimer() | ||
| for i := 0; i < b.N; i++ { | ||
| if _, err := g.SubGraphFrom(component); err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate these. Very compelling results!