Skip to content

(Perf): Optimize resolver hash-option intersection #14105

Description

@KRRT7

Constraint.__and__() currently intersects hash_options with list membership checks:

[v for v in other.hash_options[alg] if v in self.hash_options[alg]]

For each shared hash algorithm, this iterates one list and checks membership in another list. Since list membership is linear, the intersection is O(n*m).

This can be reduced to O(n+m) by building a temporary set for membership checks:

self_hashes = set(self.hash_options[alg])
[v for v in other.hash_options[alg] if v in self_hashes]

The implementation should preserve the current result ordering from other.hash_options[alg] unless we explicitly decide that hash option ordering is not observable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions