Skip to content

Python PHIR interpreter's Result decode cache grows without bound between resets #1350

Open

Description

@ciaranra

The pure-Python PHIR interpreter (PhirClassicalInterpreter, #1314 branch) caches the decoded references of each executed Result op in a plain dict keyed by the op object. The cache is cleared only by init() and reset().

A caller that builds a fresh COp("Result", ...) for every handle_cops/execute call grows the cache by one entry per call until the next reset. No caller in the repo does this today: HybridEngine executes the program's own ops. The README documents that decoded Results are held until the next init or full reset.

Direction

Bound the cache, for example by evicting entries for ops that are not part of the loaded program, or by caching only program ops. Keep the per-shot hot path free of JSON/FFI work: a WeakKeyDictionary was tried and measured 7.6% slower on the Result path, and it needed pickling hooks.

Found during the review of the #1314 work.

Activity

  1. added
    enhancementNew feature or request
    pythonPull requests that update python code
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpythonPull requests that update python code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions