Skip to content

Tweak Graphs performance, and further improve GraphPropertiesTest in light of the recently detected bug. - #8802

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1009082052
Oct 29, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1009082052

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Tweak Graphs performance, and further improve GraphPropertiesTest in light of the recently detected bug.

Graphs

  • We have been copying a Set to an ArrayDeque for no particular reason. We might as well use its Iterator to reduce how much we store.

GraphPropertiesTest

  • hasCycle_deepPathGraph was populating graphsToTest but then asserting on directedNetwork and undirectedNetwork, which are empty! (This seems like a sign that the tests should really be restructed more significantly....) This is my fault from 63734b9.
  • Because of the recently detected bug (fix: cl/1009013320), our tests weren't actually traversing deeply into the graph, so they weren't actually proving that the switch from recursion to iteration was effective. Shame on me for not verifying that the tests failed before my change!
  • Until cl/1009013320, all tests that checked for hasCycle(undirectedGraph) == true triggered a shortcut, so we were not testing the part of the logic that lives in subgraphHasCycle. This has probably been broken forever.

Amazingly, all the new and fixed tests do pass without prod changes.

(noticed during investigation of #8796)

RELNOTES=n/a

… in light of the recently detected bug.

### `Graphs`

- We have been copying a `Set` to an `ArrayDeque` for no particular reason. We might as well use its `Iterator` to reduce how much we store.

### `GraphPropertiesTest`

- `hasCycle_deepPathGraph` was populating `graphsToTest` but then asserting on `directedNetwork` and `undirectedNetwork`, which are empty! (This seems like a sign that the tests should really be restructed more significantly....) This is my fault from 63734b9.
- Because of the recently detected bug (fix: cl/1009013320), our tests weren't actually traversing deeply into the graph, so they weren't actually proving that the switch from recursion to iteration was effective. Shame on me for not verifying that the tests failed before my change!
- Until cl/1009013320, all tests that checked for `hasCycle(undirectedGraph) == true` triggered [a shortcut](https://github.com/google/guava/blob/ff4f4e8dee0cad772ffa0256a93cae5b4aae695f/guava/src/com/google/common/graph/Graphs.java#L65), so we were not testing the part of the logic that lives in `subgraphHasCycle`. This has probably been broken forever.

Amazingly, all the new and fixed tests do pass without prod changes.

(noticed during investigation of #8796)

RELNOTES=n/a
PiperOrigin-RevId: 1009644539
@copybara-service
copybara-service Bot merged commit c29059a into master Oct 29, 2026
15 checks passed
@copybara-service
copybara-service Bot deleted the test_1009082052 branch October 29, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant