Skip to content

refactor: dedupe stats reduction (#15) + name the data-loss guard (#14) - #21

Merged
mledour merged 1 commit into
mainfrom
refactor/cleanup-stats-and-guard
Jun 8, 2026
Merged

mledour merged 1 commit into
mainfrom
refactor/cleanup-stats-and-guard

Conversation

@mledour

@mledour mledour commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Findings #15 + #14 (code review): cleanup

#15ComputeStats mean/min/max triplet ×3 (+ analyze.py mirror)

ComputeStats repeated the "Kahan-Neumaier mean + min_element + max_element" triplet three times (ms / pct / gpu), and analyze.py mirrored it. Extracted one Summarize() (C++) / _summarize() (Python) so the reduction has a single source — a change to the summation strategy can no longer drift between the three stat groups or across the two languages (the exact "fixed in one branch, missed in the others" risk the review called out).

Pure refactor — the merged-CSV header is byte-identical. The 19-test analyzer suite (which checks the header exactly) still passes:

$ python3 -m pytest scripts/test_analyze.py -q
19 passed

#14 — name the data-loss invariant

The "did this session record any frames?" check was an inline g_frameCounter == 0 with a long comment. Extracted SessionRecordedFrames() as the single definition, used by MergeIntoOutput's zero-frame guard, with the rationale consolidated there (FrameCsvSink's lazy-open documented as the per-side counterpart).

Scope note: #3 already removed the worst part of #14 — the removeStale call sites — by switching the merge to write-temp-then-atomic-rename. So what remained was this naming/comment consolidation. The deeper "right altitude" fix (#13-adjacent) — per-session output filenames so a no-op session physically can't overwrite a prior one — stays deliberately deferred (keeps one file per PID; noted in commit b643964).

3 files, +53/−35; no lines over the limit.

🤖 Generated with Claude Code

…ard (#14)

#15: ComputeStats repeated the "Kahan-Neumaier mean + min_element + max_element"
triplet three times (ms / pct / gpu), and analyze.py mirrored it. Extract one
Summarize() (C++) / _summarize() (Python) so the reduction has a single source
-- a change to the summation strategy can no longer drift between the three
stat groups or across the two languages. Pure refactor: the merged-CSV header
is byte-identical (the 19-test analyzer suite, which checks the header exactly,
still passes locally).

#14: name the data-loss invariant. The "did this session record any frames?"
check was an inline g_frameCounter==0 with a long comment; extract
SessionRecordedFrames() as the single definition, used by MergeIntoOutput's
zero-frame guard, with the rationale consolidated there (FrameCsvSink's
lazy-open is documented as the per-side counterpart). Note: #3 already removed
the worst part of this finding -- the removeStale call sites -- by switching the
merge to write-temp-then-atomic-rename, so what remained was this naming /
comment consolidation; the deeper per-session-filenames fix stays deliberately
deferred (one file per PID).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mledour
mledour merged commit 49c0902 into main Jun 8, 2026
3 checks passed
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