opt(goal): minutes feeds do no word work; word rail goes count-only [cold-turkey-full-tokenization] #188

Merged
AlexKucera merged 4 commits from opt/cold-turkey-full-tokenization into main 2026-11-13 16:51:06 +01:00
4 Commits
Author SHA1 Message Date
AlexKucera 7cd5e6964e merge main (2cfd8b9) into opt branch
CI / ci (push) Canceled after 0s
CI / ci (pull_request) Canceled after 0s
Fold origin/main (2cfd8b9, #187 library-search stale-after-mutation)
into opt/cold-turkey-full-tokenization. Only conflict was the
docs/devlog/INDEX.md both-added-row; resolved keep-both in
newest-first order. No code files touched by the resolution:
Museion/ and MuseionTests/ carry #187's hunks verbatim.
2026-11-13 16:41:15 +01:00
AlexKucera 7de8e2f7a1 docs(devlog): cold-turkey full-tokenization opt branch
CI / ci (push) Canceled after 0s
CHANGELOG [Unreleased] > Changed entry + session log + INDEX row for
the unticketed opt pass (minutes feeds skip word counting; word rail
count-only; no token array per keystroke). Suite 684.
2026-11-13 04:24:04 +01:00
AlexKucera 9f4d9ef9ea perf(cold-turkey): minutes feeds skip word counting; word rail goes count-only
CI / ci (push) Canceled after 0s
Root cause (re-derived live at 5915178): WritingLockState.feed ->
WritingGoalRun.update counted words for EVERY goal type, and
DraftStats.words built the complete lowercased token array
(text.split(whereSeparator:).map(lowercased)) just to return .count —
O(document) allocation + lowercasing per keystroke on the main actor
for minutes goals whose verdict/progress/readout never read the count
(argus probe at efbde25c: minutes ~0.32/3.07/16.64 ms per update at
1k/10k/50k words, linear in document size).

Fix, two halves, semantics byte-stable:
- update(text:) guards on .words — a minutes run does no word work
  on feed at all; its accounting freezes at the arm-time baseline
  (currentWords was dead state for minutes runs: readout, isMet,
  progress, and the completion note all ride the clock).
- DraftStats.words becomes a count-only Character pass over maximal
  isLetter/isNumber runs — never materializing the lowercased
  [String]. Identical count by construction: the tokenizer's split
  (which always omits empty subsequences) yields exactly the maximal
  runs; equivalence pinned against the split expression over a
  mixed-script/emoji/punctuation/number corpus in DraftStatsTests.

WritingGoalRun.init (arm-time baseline) keeps counting once per arm
through the same rail — now also allocation-free. Callers unchanged
(update's countWords defaults to DraftStats.words); the words-goal
net accounting is pinned unchanged ('a words update takes exactly
one word-rail trip' + all existing net-delta pins).
2026-11-13 04:21:28 +01:00
AlexKucera dde99c8a75 test(goal): pin zero word-rail trips for minutes updates (RED)
CI / ci (push) Canceled after 0s
The argus opt pass (2026-11-09, unticketed digest finding
cold-turkey-full-tokenization): every editor keystroke feeds the whole
document through WritingGoalRun.update, which counted words for ALL
goal types — a minutes verdict ignores the count, so the feed paid
whole-document tokenization (lowercased [String] allocation) per
keystroke on the main actor for nothing (argus probe: ~16.6 ms/update
at 50k words, linear in document size).

Pins, RED-first where constructible:
- WritingGoalTests 'a minutes update takes zero word-rail trips' —
  RED at base (base takes one trip per update).
- WritingGoalTests 'a words update takes exactly one word-rail trip' —
  the skip boundary: words goals keep live accounting.
- DraftStatsTests 'word rail equals the split tokenizer over a mixed
  corpus' — semantic equivalence pin (old split expression as inline
  reference over mixed scripts, emoji, punctuation, numbers,
  empties); green at base by design — it is the equivalence proof.

Instrument: update(text:countWords:) gains an injectable word-rail
seam (default DraftStats.words) — per-call counting instead of a
global counter, which would race the hosted suite's parallel
DraftStats calls. No behavior change in this commit; update still
counts for every goal.
2026-11-13 04:20:15 +01:00