Skip to content

Optimize slice comparison utility - #1209

Merged
InfiniteStash merged 2 commits into
stashapp:masterfrom
slick-daddy:codex/locate-and-optimize-hot-path
Aug 26, 2026
Merged

Optimize slice comparison utility#1209
InfiniteStash merged 2 commits into
stashapp:masterfrom
slick-daddy:codex/locate-and-optimize-hot-path

Conversation

@slick-daddy

@slick-daddy slick-daddy commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

The existing SliceCompare performed repeated linear membership scans which is O(n*m) and is hot in edit paths that compare aliases/images/tags, so lowering complexity will reduce CPU on those paths.

Description

  • Replace repeated Includes linear scans in SliceCompare with prebuilt set maps via a new makeSet helper to achieve O(n) lookups and reduce overall work in comparisons in pkg/utils/slice_compare.go.
  • Add small maps (addedSet and missingSet) to suppress duplicates while preserving the original output order semantics of SliceCompare.
  • Add a benchmark BenchmarkSliceCompare in pkg/utils/slice_compare_test.go exercising two 1,000-item slices with partial overlap to guard future regressions and measure improvements.
  • Keep Includes available for callers that rely on it while centralizing set construction in makeSet for reuse and readability.

Drafted with Codex.

Edits usually don't include many objects, so practical change can be limited.

@InfiniteStash

Copy link
Copy Markdown
Collaborator

Thanks! I removed the benchmark and tweaked a bit.

@InfiniteStash
InfiniteStash merged commit b2243dc into stashapp:master Aug 26, 2026
5 checks passed
@slick-daddy
slick-daddy deleted the codex/locate-and-optimize-hot-path branch August 26, 2026 11:08
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.

2 participants