Optimize inventory.Diff with map lookup - #1720
Merged
stefanprodan merged 1 commit intoAug 1, 2026
Merged
Conversation
Replace the O(n) versionOf closure with a map built once upfront, reducing complexity from O(n*m) to O(n+m). On large inventories this avoids redundant linear scans on every prune cycle. Signed-off-by: manoj-1407 <manojkumar148700@gmail.com> Assisted-by: Claude/claude-sonnet-4-6
stefanprodan
approved these changes
Jul 31, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this change do?
inventory.Diffused aversionOfclosure that performed a linearscan through all inventory entries on every call — once per item in
the diff list. For an inventory with
nentries and a diff list ofmitems, this is O(n*m).This change builds a version map once upfront (O(n)), then uses O(1)
map lookups per diff item, reducing overall complexity to O(n+m).
On clusters with large inventories this avoids redundant linear scans
on every reconciliation cycle where pruning is needed.
Testing
Existing
Test_Inventory/diff_objects_in_inventorypasses withoutmodification — behavior is identical, only the lookup strategy changed.