Skip to content

Isolated heap mode: subprocess memray pass for an order-independent baseline #20

@FBumann

Description

@FBumann

Note

Rescoped under #38 (unified multi-metric memory model). This is the isolated heap
mode
— i.e. running the memray pass in a subprocess for an order-independent baseline. It
reuses #38/#34's shared fork+wait4+gc.freeze()+baseline machinery rather than its own;
this issue is just the heap-specific surfacing of it. Original proposal below.


Found wiring pytest-benchmem into linopy's benchmark suite.

In-process measurement is fine generally, but linopy builds models via solvers with C-level allocations that aren't always freed between tests in one process — so a peak can be influenced by earlier tests. linopy's old engine ran each phase in its own subprocess for a clean baseline.

Proposed
Add --benchmark-memory-isolate (and a matching fixture/option) that runs each measured action's memray pass in a forked/spawned subprocess and returns the peak — a clean baseline per measurement. In-process stays the default.

Acceptance

  • With the flag, each measurement runs in its own process; peaks are independent of test order.
  • Without it, behavior is unchanged.

Notes

  • Action must be forkable (posix fork is simplest; document the spawn/pickle caveat).
  • Pairs with --benchmark-memory-repeats.

Need: accuracy for native-allocation libraries without forcing subprocess cost on every consumer.

🤖 Issue drafted by Claude from the linopy integration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions