perf(cold-turkey): minutes feeds skip word counting; word rail goes count-only
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Root cause (re-derived live at5915178): 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 atefbde25c: 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).
This commit is contained in:
1 parent
dde99c8a75
commit
9f4d9ef9ea
2 files changed
+37
-11
No files matched your search
@@ -79,10 +79,28 @@ nonisolated struct DraftStats: Equatable {
|
||||
|
||||
/// Word count over the same token semantics every text metric
|
||||
/// rides (#161: Cold Turkey net-words counts with this — one
|
||||
/// tokenizer, no drift). "writer's" is two words here, headings
|
||||
/// word rail, no drift). "writer's" is two words here, headings
|
||||
/// are body text, frontmatter is not (the editor never shows it).
|
||||
/// Count-only (opt pass 2026-11-09): one Character pass counting
|
||||
/// maximal isLetter/isNumber runs — the lowercased [String] the
|
||||
/// per-keystroke editor feed once paid for is never built. Equal
|
||||
/// to the tokenizer's split by construction (omitting empty
|
||||
/// subsequences leaves exactly the maximal runs); pinned against
|
||||
/// the split expression over a mixed-script corpus.
|
||||
static func words(in text: String) -> Int {
|
||||
tokens(in: text).count
|
||||
var count = 0
|
||||
var inRun = false
|
||||
for character in text {
|
||||
if character.isLetter || character.isNumber {
|
||||
if !inRun {
|
||||
count += 1
|
||||
inRun = true
|
||||
}
|
||||
} else {
|
||||
inRun = false
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
/// Lowercased runs of Characters where isLetter || isNumber — the
|
||||
|
||||
Reference in new issue
Block a user