Skip to content

[WIP] Enhance MTLN performance by optimizing bundle processing and reducing…#401

Draft
lmdiazangulo wants to merge 11 commits intodevfrom
400-mtln-cpu-performance-improvements
Draft

[WIP] Enhance MTLN performance by optimizing bundle processing and reducing…#401
lmdiazangulo wants to merge 11 commits intodevfrom
400-mtln-cpu-performance-improvements

Conversation

@lmdiazangulo
Copy link
Copy Markdown
Contributor

… unnecessary computations

lmdiazangulo and others added 11 commits May 4, 2026 12:40
… unnecessary computations

Co-authored-by: Copilot <copilot@github.com>
Use ngspice's built-in 'save none' mode to prevent unbounded
accumulation of plot vector history during time-stepping.

In shared-library mode, ngspice's plotAddRealValue() checks a
'savenone' flag (set when 'save none' is in the saves list). When
true it resets v_length=0 before each write, keeping only the
latest data point instead of appending. vlength2delta() also
returns 1, so the underlying allocation never grows beyond a
single slot.

Call 'save none' after circ() loads the circuit description so
that ft_curckt is non-NULL. The savenone flag then persists for
the entire simulation (it is never reset to FALSE), fixing the
linear memory growth that occurred on every resume() call.

updateNodes() reads values(ubound(values,1)) which still returns
the correct latest value with a length-1 vector.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Three changes to eliminate step-count-proportional RSS growth:

1. ngspice control.c (submodule): Free the struct control chain after
   each top-level command execution in cp_evloop(). Every call to
   ngSpice_Command() previously accumulated a new struct control node
   with a wl_copy() of the parsed command that was never freed. With
   N alter calls per step this produced ~4 KB/step growth.

2. circuit.F90: Add 'set history = 1' after 'save none' to limit
   ngspice command history to 1 entry. Without this, the first 10000
   commands (cp_maxhistlength default) accumulate before freeing.

3. probes.F90 / mtln_solver.F90 / observation.F90: Pre-allocate
   only a single frame buffer for MTLN observation probes instead of
   N frames (one per timestep). The single slot is overwritten each
   step; results are written to output at observation time.

Result: RSS is now constant across step counts (50, 500, 5000 steps
all show ~145 MB with the debug binary, vs. +22 MB growth before).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants