quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.28k stars 1.02k forks source link

Optimize cached_method when wrapping no-arg methods #6381

Closed maffoo closed 11 months ago

maffoo commented 11 months ago

Previously, the first time a no-arg cached method was called the decorator would make three calls: hasattr, object.__setattr__, getattr, and when called subsequently it would make two calls: hasattr, getattr. Here we refactor the implementation to use a sentinel value so that on the first call we only make two calls: getattr, object.__setattr__, and when called subsequently we only make a single getattr call.

codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (ec727ca) 97.81% compared to head (fbb6635) 97.80%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6381 +/- ## ========================================== - Coverage 97.81% 97.80% -0.01% ========================================== Files 1111 1111 Lines 96948 96951 +3 ========================================== - Hits 94825 94824 -1 - Misses 2123 2127 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.