Skip to content

Optimize keys of the memoization cache#119

Merged
jdaymude merged 8 commits intomainfrom
cache-key
Oct 3, 2025
Merged

Optimize keys of the memoization cache#119
jdaymude merged 8 commits intomainfrom
cache-key

Conversation

@Garrett-Pz
Copy link
Collaborator

@Garrett-Pz Garrett-Pz commented Oct 1, 2025

Remove MemoizeMode::FragsIndex and update remaining memoization cache keys to Vec<usize>, which are faster to hash. Specifically, MemoizeMode::CanonIndex now assigns every canonical labeling computed by canonize::canonize a unique usize canonical identifier. An assembly state's memoization cache key is now a sorted list of canonical IDs corresponding to its fragments.

@Garrett-Pz Garrett-Pz requested a review from jdaymude October 2, 2025 16:35
@jdaymude jdaymude added the optimization An optimization to existing implementation label Oct 2, 2025
@jdaymude jdaymude changed the title Change the keys of the memoization cache. Change keys of the memoization cache to Vec<usize> Oct 2, 2025
@jdaymude jdaymude changed the title Change keys of the memoization cache to Vec<usize> Change keys of the memoization cache Oct 2, 2025
@jdaymude jdaymude changed the title Change keys of the memoization cache Optimize keys of the memoization cache Oct 2, 2025
@jdaymude
Copy link
Contributor

jdaymude commented Oct 3, 2025

Benchmark results vs. `v0.5.1` as a baseline

These include universal improvement on bench_bounds, with 10–78% improvements on coconut_55.

bench_enumerate/gdb13_1201/extend
                        time:   [25.486 ms 25.491 ms 25.498 ms]
                        change: [-4.6190% -4.5691% -4.5195%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/gdb13_1201/grow-erode
                        time:   [12.274 ms 12.277 ms 12.281 ms]
                        change: [-1.8223% -1.7759% -1.7296%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/gdb17_200/extend
                        time:   [360.91 ms 360.95 ms 361.00 ms]
                        change: [-6.6960% -6.6389% -6.5851%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/gdb17_200/grow-erode
                        time:   [111.29 ms 111.34 ms 111.39 ms]
                        change: [-7.3102% -7.2459% -7.1855%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/checks/extend
                        time:   [138.10 ms 138.20 ms 138.31 ms]
                        change: [-8.5431% -8.4401% -8.3307%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/checks/grow-erode
                        time:   [31.168 ms 31.176 ms 31.183 ms]
                        change: [-6.2755% -6.2053% -6.1403%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/coconut_55/extend
                        time:   [1.2053 s 1.2056 s 1.2059 s]
                        change: [-5.5101% -5.4728% -5.4351%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_enumerate/coconut_55/grow-erode
                        time:   [266.08 ms 266.15 ms 266.22 ms]
                        change: [-6.7591% -6.7172% -6.6778%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_canonize/gdb13_1201/nauty
                        time:   [112.12 ms 112.19 ms 112.26 ms]
                        change: [+3.1710% +3.2530% +3.3417%] (p = 0.00 < 0.05)
                        Performance has regressed.
bench_canonize/gdb13_1201/tree-nauty
                        time:   [53.620 ms 53.646 ms 53.669 ms]
                        change: [+1.3378% +1.3993% +1.4565%] (p = 0.00 < 0.05)
                        Performance has regressed.
bench_canonize/gdb17_200/nauty
                        time:   [2.7710 s 2.7731 s 2.7751 s]
                        change: [+1.2370% +1.3351% +1.4315%] (p = 0.00 < 0.05)
                        Performance has regressed.
bench_canonize/gdb17_200/tree-nauty
                        time:   [1.0822 s 1.0841 s 1.0859 s]
                        change: [+0.3011% +0.4913% +0.6714%] (p = 0.00 < 0.05)
                        Change within noise threshold.
bench_canonize/checks/nauty
                        time:   [1.2000 s 1.2085 s 1.2172 s]
                        change: [-3.8419% -3.1775% -2.4189%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_canonize/checks/tree-nauty
                        time:   [407.28 ms 407.93 ms 408.62 ms]
                        change: [-0.0287% +0.1828% +0.3798%] (p = 0.10 > 0.05)
                        No change in performance detected.
bench_canonize/coconut_55/nauty
                        time:   [11.745 s 11.838 s 11.931 s]
                        change: [-3.5294% -2.7080% -1.9284%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_canonize/coconut_55/tree-nauty
                        time:   [3.9905 s 3.9937 s 3.9967 s]
                        change: [+0.0226% +0.1428% +0.2604%] (p = 0.03 < 0.05)
                        Change within noise threshold.

bench_bounds/gdb13_1201/no-bounds
                        time:   [51.594 ms 51.898 ms 52.177 ms]
                        change: [-18.206% -17.586% -17.000%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb13_1201/log
                        time:   [50.616 ms 50.954 ms 51.298 ms]
                        change: [-12.608% -11.914% -11.235%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb13_1201/int
                        time:   [46.683 ms 46.971 ms 47.290 ms]
                        change: [-5.0849% -4.2812% -3.4648%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb13_1201/int-vec
                        time:   [46.370 ms 46.600 ms 46.819 ms]
                        change: [-3.1511% -2.3430% -1.5853%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb17_200/no-bounds
                        time:   [321.97 ms 325.46 ms 328.87 ms]
                        change: [-73.857% -73.411% -72.988%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb17_200/log
                        time:   [278.01 ms 280.22 ms 282.43 ms]
                        change: [-63.591% -63.236% -62.897%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb17_200/int
                        time:   [85.457 ms 85.771 ms 86.079 ms]
                        change: [-50.017% -49.692% -49.394%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/gdb17_200/int-vec
                        time:   [66.170 ms 66.450 ms 66.728 ms]
                        change: [-12.857% -12.408% -11.946%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/checks/no-bounds
                        time:   [273.93 ms 284.95 ms 299.64 ms]
                        change: [-75.423% -74.137% -72.607%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/checks/log time:   [181.29 ms 184.68 ms 188.00 ms]
                        change: [-61.079% -60.015% -59.070%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/checks/int time:   [30.459 ms 30.776 ms 31.083 ms]
                        change: [-66.104% -65.128% -64.231%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/checks/int-vec
                        time:   [11.654 ms 11.713 ms 11.782 ms]
                        change: [-26.381% -25.609% -24.784%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/coconut_55/no-bounds
                        time:   [3.5605 s 3.6421 s 3.7182 s]
                        change: [-79.049% -78.471% -77.864%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/coconut_55/log
                        time:   [3.3160 s 3.3668 s 3.4170 s]
                        change: [-76.646% -75.963% -75.237%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/coconut_55/int
                        time:   [321.01 ms 327.36 ms 333.40 ms]
                        change: [-60.115% -58.731% -57.526%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_bounds/coconut_55/int-vec
                        time:   [206.82 ms 210.27 ms 213.21 ms]
                        change: [-12.116% -9.9580% -8.0124%] (p = 0.00 < 0.05)
                        Performance has improved.

bench_memoize/gdb13_1201/no-memoize
                        time:   [23.327 ms 23.736 ms 24.357 ms]
                        change: [-5.7462% +2.8449% +11.869%] (p = 0.54 > 0.05)
                        No change in performance detected.
bench_memoize/gdb13_1201/nauty-index
                        time:   [48.698 ms 49.088 ms 49.502 ms]
                        change: [-4.4699% -3.4780% -2.4538%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_memoize/gdb13_1201/tree-nauty-index
                        time:   [46.309 ms 46.675 ms 47.007 ms]
                        change: [-2.3466% -1.4214% -0.5180%] (p = 0.01 < 0.05)
                        Change within noise threshold.
bench_memoize/gdb17_200/no-memoize
                        time:   [56.901 ms 57.303 ms 57.718 ms]
                        change: [+10.370% +11.362% +12.486%] (p = 0.00 < 0.05)
                        Performance has regressed.
bench_memoize/gdb17_200/nauty-index
                        time:   [69.047 ms 69.321 ms 69.650 ms]
                        change: [-22.020% -21.574% -21.113%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_memoize/gdb17_200/tree-nauty-index
                        time:   [66.070 ms 66.358 ms 66.648 ms]
                        change: [-13.293% -12.790% -12.274%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_memoize/checks/no-memoize
                        time:   [13.199 ms 13.507 ms 13.740 ms]
                        change: [+12.663% +15.558% +18.352%] (p = 0.00 < 0.05)
                        Performance has regressed.
bench_memoize/checks/nauty-index
                        time:   [12.039 ms 12.067 ms 12.095 ms]
                        change: [-46.984% -45.859% -44.806%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_memoize/checks/tree-nauty-index
                        time:   [11.652 ms 11.709 ms 11.781 ms]
                        change: [-28.227% -26.957% -25.865%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_memoize/coconut_55/no-memoize
                        time:   [344.14 ms 351.64 ms 358.15 ms]
                        change: [+9.4051% +13.260% +17.480%] (p = 0.00 < 0.05)
                        Performance has regressed.
bench_memoize/coconut_55/nauty-index
                        time:   [209.28 ms 212.59 ms 215.79 ms]
                        change: [-22.666% -20.899% -19.116%] (p = 0.00 < 0.05)
                        Performance has improved.
bench_memoize/coconut_55/tree-nauty-index
                        time:   [205.01 ms 208.99 ms 212.49 ms]
                        change: [-12.968% -10.648% -8.6130%] (p = 0.00 < 0.05)
                        Performance has improved.

Interestingly, implementing a critical part of this update using the more elegant entry API for Rust maps (see the canonical_id function of commit 7d293a4) is much worse. For example, the entry API version is 22–857% slower on coconut_55 than the direct get/insert implementation, and individual memoization operations are up to twice as slow.

@jdaymude jdaymude marked this pull request as ready for review October 3, 2025 00:02
@jdaymude jdaymude merged commit acd9654 into main Oct 3, 2025
11 checks passed
@jdaymude jdaymude deleted the cache-key branch October 3, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization An optimization to existing implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants