Skip to content
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

Replace level assignment algo #31

Merged
merged 5 commits into from
Sep 20, 2022
Merged

Replace level assignment algo #31

merged 5 commits into from
Sep 20, 2022

Conversation

oowekyala
Copy link
Collaborator

I suspected the algorithm is exponential for some types of graph, and measured that this is the case. This PR replaces the algo with something that stays linear. I also compared with the algorithm used by the C++ runtime (ported to Rust). The Rust algorithm of this PR scales better on this specific type of graph, but I didn't do any tests on more normal graphs. This is anyway not a performance critical part of the runtime, but this TODO comment had been irking me for a while....

Here's a graph produced by the benhmarking framework. The "old" curve is the current algorithm, the "new" one is the one introduced in this PR. The graph is similar to the chain of diamonds described in the removed TODO comment (see changes). The chain length is the x axis of the graph.

lines

Level assignment/old/10 time:   [4.6777 µs 4.6968 µs 4.7203 µs]
                        change: [+29.037% +29.475% +29.944%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) low mild
  7 (7.00%) high mild
  1 (1.00%) high severe
Level assignment/new/10 time:   [3.6707 µs 3.6766 µs 3.6832 µs]
                        change: [-15.488% -15.232% -14.986%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe
Level assignment/old/20 time:   [16.975 µs 17.010 µs 17.048 µs]
                        change: [+139.46% +141.70% +143.47%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
Level assignment/new/20 time:   [6.9723 µs 6.9910 µs 7.0104 µs]
                        change: [-60.509% -60.295% -60.080%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
Level assignment/old/30 time:   [38.714 µs 38.816 µs 38.929 µs]
                        change: [+269.68% +271.00% +272.37%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 6 outliers among 100 measurements (6.00%)
  6 (6.00%) high mild
Level assignment/new/30 time:   [10.633 µs 10.658 µs 10.686 µs]
                        change: [-72.727% -72.645% -72.561%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  3 (3.00%) high severe
Level assignment/old/60 time:   [152.78 µs 153.18 µs 153.61 µs]
                        change: [+643.88% +647.00% +649.97%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
Level assignment/new/60 time:   [20.442 µs 20.586 µs 20.822 µs]
                        change: [-86.798% -86.734% -86.664%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  7 (7.00%) high mild
  2 (2.00%) high severe
Level assignment/old/120
                        time:   [651.89 µs 653.46 µs 655.03 µs]
                        change: [+1547.9% +1553.7% +1559.5%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
Level assignment/new/120
                        time:   [40.250 µs 40.348 µs 40.448 µs]
                        change: [-93.739% -93.721% -93.703%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
The best of the three is the new rust algo
@cmnrd
Copy link
Contributor

cmnrd commented Sep 19, 2022

Cool! Can you share any details about the dependency graph structure that you used for your experiments?

@oowekyala
Copy link
Collaborator Author

The dependency graph looks like this:
Bildschirmfoto vom 2022-09-19 10-12-07

It is a chain of small identical subgraphs, which each contain a long path and a short path from the source to the exit. The number of these subgraphs is the parameter for the test (in the screenshot, 3, but in the benchmark 10 to 120). The old algorithm is bad with this structure because it performs breadth first search, and its frontier set grows much more than necessary. It starts with the root, but after 3 iterations the frontier set contains Reaction(r[0]/1) and Port(r[0]/out) (red nodes), because the shortest path from the root to these nodes has length 3. The successors of each of these will be explored separately, which duplicates work. After 6 iterations the frontier set is all the turquoise nodes (nodes reachable in three steps from any red node), and it keeps growing.

Copy link
Contributor

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cmnrd cmnrd merged commit 98c6239 into main Sep 20, 2022
@cmnrd cmnrd deleted the clem.new-graph-search branch September 20, 2022 22:33
@lhstrh lhstrh added the enhancement New feature or request label Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants