Closed maffoo closed 9 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
6d437c4
) 97.80% compared to head (88018d7
) 97.81%.:exclamation: Current head 88018d7 differs from pull request most recent head a181472. Consider uploading reports for the commit a181472 to get more accurate results
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
- Is there anything in the standard library for doing this automatically?
I don't know of anything to do this automatically. Which is unfortunate because it seems like a rather natural thing to do, and in fact I think we could improve performance by doing this for other heavily-used cirq classes as well.
- should we limit the cache size? What If I make, run/simulate, and garbage-collect a whole lot of circuits on a whole lot of different qubits?
We could do that, though I suspect it's not common to create so many different qubits that this would matter.
Changed to use a WeakValueDictionary for caching.
Here we add caches of common qubit types
GridQubit
,LineQubit
, andNamedQubit
(and their associatedQid
types) so that we can reuse instances of these objects. Operations on these objects are extremely common, so reusing instances can have significant performance benefits, in particular because hashes do not need to be recomputed and equality comparisons can be short-circuited with instance equality in common cases.