Files
clean-architecture-frontend…/tests/unit/realtime
DongHyeonkaandClaude Opus 5.5 df9b15c039 fix(realtime): parse SSE text a line at a time (R-4.4)
consumeText() walked every code point, appended it to the line string and
called TextEncoder.encode() on it to count UTF-8 bytes, so a 250KB chunk
allocated ~250k arrays on the main thread.

It now finds the next CR/LF with one regex scan, appends the text before it
as one slice and encodes that slice once for its byte count. Byte counts only
grow within a line, so checking the line/incomplete-buffer limits per segment
fails on exactly the same inputs as the per-character check. BOM, pending CR
across reads, CRLF terminator bytes and QUEUE_OVERFLOW ordering are unchanged.

Correctness: existing parser tests pass unchanged. New tests (all green on
the old parser first, as characterization): whole vs byte-by-byte input with
CRLF, CR-only, multi-line data, BOM and a mid-stream U+FEFF, 2/3/4-byte
UTF-8 split across reads; trailing CR blank line dispatched at finish; UTF-8
bytes (not UTF-16 units) counted against line and event limits, also when a
multibyte character is split across reads; a max-size line over 1,000-byte
reads accepted and one byte more rejected; a 248,780-byte chunk of 200
events.

Benchmark (throwaway script, not committed; Node 24.14; 200 events in one
~250KB chunk; machine under load avg 39-54 on 22 cores, so numbers are noisy):
- old/new interleaved in one process, forced GC before each run, median:
  ASCII 248,780 B: 294-345 ms -> 4.3-8.2 ms (36-80x)
  multibyte 248,180 B (Korean/emoji/accented): 95-130 ms -> 19-26 ms (~5x)
- each parser standalone, sequential runs, average:
  ASCII: 664-764 ms -> 0.9-3.7 ms
  multibyte: 155-196 ms -> 1.5-6.3 ms
Remaining cost of the new parser is mostly native TextDecoder/TextEncoder
work (profiled); a JS charCode loop for the byte count was not faster.

Gates: check:architecture, check:types:app, check:types:test, lint,
test:component pass. test:unit passes except removal-fixture.test.ts, which
needs generated artifacts/release evidence absent from this fresh worktree
(unrelated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 12:19:48 +09:00
..
2026-08-01 19:39:59 +09:00
2026-07-30 15:58:20 +09:00