Skip to content

[Cleanup] Remove dead client variable, use Buffer.indexOf for newline counting, document source maps - #170

Merged
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-139-3sr1lh
Aug 16, 2026
Merged

[Cleanup] Remove dead client variable, use Buffer.indexOf for newline counting, document source maps#170
LarsLaskowski merged 1 commit into
mainfrom
claude/issue-139-3sr1lh

Conversation

@LarsLaskowski

@LarsLaskowski LarsLaskowski commented Aug 16, 2026

Copy link
Copy Markdown
Owner

📖 Description

Bundles three independent, minor housekeeping items from the 2026-07 security & performance review:

  1. src/client/main.ts — removed the dead displayedLines variable in the SSE log-line handler. It was declared but never assigned, always null, and passed into completeSseTiming's perf-timing details. The real displayed-line count is already recorded separately by the render-side render:log-lines timing, since the actual render is deferred to a requestAnimationFrame batch.
  2. src/server/logTailer.ts — replaced the byte-by-byte for…of loop counting \n bytes in readLastLines with Buffer.prototype.indexOf, which performs the same scan natively instead of one JS iteration per byte. This path can scan up to MAX_TAIL_SCAN_BYTES (8 MB) on bootstrap, reattach, and skip-ahead. Semantics are unchanged (0x0a never appears as a UTF-8 continuation byte, per the existing comment, which is preserved).
  3. README.md — added a short note documenting that client source maps are built and served intentionally (to ease in-browser debugging; the source is public anyway), and that the server-side map is not exposed since express.static only serves dist/client.

None of these changes alter user-visible behavior.

🎫 Issues

Closes #139

👩‍💻 Reviewer Notes

The readLastLines change is the one with the most surface area — worth a close look at src/server/logTailer.ts. The new regression tests exercise CRLF input, a file without a trailing newline, and a file spanning multiple 64 KB read chunks with zero newlines, to confirm the indexOf-based scan behaves identically to the removed byte loop.

📑 Test Plan

  • Added src/server/logTailer.test.ts cases:
    • normalizes CRLF line endings the same way as LF on bootstrap
    • returns the trailing line even when the file does not end with a newline
    • counts newlines correctly across multiple 64 KB read chunks (regression for #139)
  • Ran npm test (all 155 tests pass) and npm run typecheck.
  • Ran npm run build to confirm both bundles build cleanly.

✅ Checklist

General

  • I have added unit tests for my changes, per UNIT_TESTS.md.
  • I have run npm test and npm run typecheck locally and they pass.
  • I have updated the project documentation (README, ARCHITECTURE, etc.) to reflect my changes, where applicable.
  • I have read the CONTRIBUTING documentation and followed the project's code style and conventions.

Server-specific (src/server)

  • I have added or updated a module in src/server (tailer, parser, buffer, routes, SSE hub, config, etc.).
  • I have kept src/server/types.ts in sync with src/client/state.ts for any shared payload change (no shared payload change in this PR).
  • I have preserved existing server-side bounds and defaults (buffer/SSE limits, poll interval clamps) unless the change explicitly targets them.

Client-specific (src/client)

  • I have added or updated a client module (render.ts, main.ts, derivedLogView.ts, filters.ts, preferences.ts, etc.).
  • I have kept the frontend framework-free and added any new default UI state to createInitialState() in src/client/state.ts (no new state introduced).
  • I have kept every physical log line as its own visible UI row (continuation lines are not merged).

⏭ Next Steps

None.

- Remove dead `displayedLines` variable from the SSE log-line handler
  in main.ts; it was never assigned and always null.
- Use Buffer.indexOf for newline counting in readLastLines instead of
  a byte-by-byte JS loop, avoiding up to ~8M JS iterations on worst-case
  bootstrap/reattach/skip-ahead scans.
- Document in README.md that client source maps are built and served
  intentionally, to ease in-browser debugging.
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit 196eb14 into main Aug 16, 2026
10 checks passed
@LarsLaskowski
LarsLaskowski deleted the claude/issue-139-3sr1lh branch August 16, 2026 13:33
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.

Minor cleanups: dead displayedLines variable in main.ts, byte-loop newline counting in readLastLines, README note on served source maps

2 participants