Skip to content

Speedup ChainMap #98766

Closed as not planned
Closed as not planned
@zrothberg

Description

@zrothberg

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.

Metadata

Metadata

Assignees

Labels

performancePerformance or resource usagestdlibPython modules in the Lib dirtype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions