-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Speedup ChainMap #98766
Copy link
Copy link
Closed as not planned
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Makes ChainMaps iter, copy, and parents methods lazier.
Pitch
Use itertools to reduce number of objects created. Trying to claw back performance loss due to switching to an order preserving iter method.
While this method is roughly 3 times faster then the current behavior for iter it is still ~5 times slower then sets were originally based on testing high collision chainmaps. In order to get back to the original performance there would either need to be an order preserving set object or a new method added to dict that can copy hashes without copying or accessing the underlying items. The later of which seems much easier to do but the former has more general use cases. I am unsure if any other of the custom dict objects also have suboptimal structures being used that an ordered set would resolve. I believe most of the time it's suggested to just use dict in place of an ordered set.
Previous discussion
https://bugs.python.org/issue32792
The solution I went with was based on the above discussions rejected solution.
#86653
The above change inadvertently added a major performance regression by creating multiple new dicts that caused hash to be called on every object. This removed any benefit to using update over a single iterable based constructor.
No discussion on the list slicing stuff I can find. Was an inadvertent discovery when working on the iter method.