Skip to content

Avoid defensive copying in keys protocols  #5557

@daxfohl

Description

@daxfohl

Measurement and control keys protocols both do defensive copies before returning. However they are also used in hot loops where perf is important. It's likely better to specify that dunders should return return a frozenset instead, especially since most ops will return an empty one, which is a singleton requiring no allocation.

This may be impossible to do in a completely non breaking way, however I can't think of a reason users would rely on these returning mutable sets.

Update: The mypy types of the return values is AbstractSet, not Set. And FrozenSet is also a subclass of AbstractSet so this is not breaking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/protocolskind/design-issueA conversation around designtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions