Improve ComponentMap / ComponentSet#3970
Open
jsiirola wants to merge 32 commits into
Open
Conversation
…nt is not callable
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3970 +/- ##
========================================
Coverage 90.12% 90.12%
========================================
Files 909 909
Lines 108561 108676 +115
========================================
+ Hits 97836 97947 +111
- Misses 10725 10729 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Fixes #755
Summary/Motivation:
This PR Updates
COmponentMap/ComponentSetto prevent key collisions betweenints and theid()of unhashable Components. The final solution proposed here is to store all keys coming fromid()as a 2-tuple (combined with an internal class "flag"). This ended up being significantly more efficient than building a specializedHashKeyclass that would store theid()and not compare equal toint.These changes make
ComponentMap/ComponentSetslightly slower (~10-12%). To mitigate this, the PR includes two new containers, 'ObjectIdMapandObjectIdSet. These containers are more efficient than theComponentMap/ComponentSet, and approach the efficiency of a direct (manual) "dict-of-ids" implementation (see below).As part of developing this PR, several other improvements were implemented:
ComponentMap:.keys(),.values(), and.items()to match the behavior ofdictKeyErrors raised here match those raised bydictComponentMapto another.update()API / behavior matchdictComponentSet:ComponentSetto another.update()API / behavior matchsetExpressionReplacementVisitorto officially acceptComponentMapfor the substitution mapPerformance data
Given the following test code:
The original
ComponentMap/ComponentSetimplementation (from main), tested with 100k shots on Python 3.10 - 3.14:Results for the same tests on this PR:
And if we use
ObjectIdMap()/ObjectIdSetin lieu of theComponentMap/ComponentSet:Changes proposed in this PR:
AI-Use Disclosure
or
AI tools contributed to the development of this PR
Review process (select ONE):
Notes for reviewers (optional):
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: