Skip to content

Make full_name a cached_property - #7706

Merged
Jens Hedegaard Nielsen (jenshnielsen) merged 2 commits into
microsoft:mainfrom
jenshnielsen:full_name_to_cached_property
Nov 20, 2026
Merged

Jens Hedegaard Nielsen (jenshnielsen) merged 2 commits into
microsoft:mainfrom
jenshnielsen:full_name_to_cached_property

Conversation

@jenshnielsen

@jenshnielsen Jens Hedegaard Nielsen (jenshnielsen) commented Dec 11, 2025 •

Copy link
Copy Markdown
Collaborator

In examples without instrument communication / significant data storage full_name contributes significantly to runtime of measurements.

TODO

  • Profile that this matters for real examples. See notes in changelog + asv
  • Does this have any negative consequences. i.e. for dynamic parameters. Do we support dynamically changing parent. Changed the logic to ensure this does not apply for instruments that dynamically change names

@codecov

codecov Bot commented Dec 11, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.78%. Comparing base (29fe8a6) to head (ddd037a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7706      +/-   ##
==========================================
+ Coverage   77.76%   77.78%   +0.02%     
==========================================
  Files         308      308              
  Lines       32855    32888      +33     
==========================================
+ Hits        25549    25582      +33     
  Misses       7306     7306              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

In examples without instrument communication / significant data
storage full_name contributes significantly to runtime of
measurements. E.g. In an example such as
dond(
    LinSweep(dac.ch1, start=0, stop=1, num_points=50000),
    dmm.v1(),
    show_progress=False,
)

It contributes 4 s out of 30 s to the runtime.
Keep the public full_name a read-only property, since overriding a
property with a cached_property (or vice versa) is rejected by
pyright, and cached_property on top of abstractmethod drops the
abstractness. Only cache the name if the component and all its
parents use the default name_parts and short_name, which only
depend on attributes set at creation. Subclasses that override
these, e.g. to rename a module after its children were created,
keep computing the name on every access. Do not cache the name of
Function, whose name is a mutable public attribute.

Add an asv benchmark for station snapshots and Measurement.run,
tests for names after close and for overridden naming, and a
newsfragment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the conditional name-caching changes.

No open issues 🎉

What changed in this PR

This PR reduces name-resolution overhead in QCoDeS by caching full_name for components with default, static naming while preserving dynamic name resolution for overridden naming properties.

Changes:

  • Add conditional name caching for instruments, modules, channel tuples, and parameters.
  • Add regression tests for dynamic naming and name resolution after instrument closure.
  • Add station snapshot and measurement-startup benchmarks, plus a release note describing the performance improvement.
File Description
tests/​test_instrument.py Test dynamic naming and name resolution after closure.
tests/​parameter/​test_parameter_basics.py Test uncached names when parameter naming is overridden.
src/​qcodes/​parameters/​parameter_base.py Cache parameter names when parameter and instrument naming are static.
src/​qcodes/​instrument/​instrument_base.py Add conditional caching for instrument names.
src/​qcodes/​instrument/​channel.py Extend caching checks to modules and channel tuples.
docs/​changes/​newsfragments/​7706.improved Document caching behavior and snapshot performance gains.
benchmarking/​benchmarks/​station.py Benchmark snapshots and measurement startup with nested instruments.

Review effort: Balanced

Merged via the queue into microsoft:main with commit 09da3b4 Nov 20, 2026
19 checks passed
@jenshnielsen
Jens Hedegaard Nielsen (jenshnielsen) deleted the full_name_to_cached_property branch November 20, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants