[PR #3111] [MERGED] chore(client): fully opt-in render-timing diagnostics (pins #3104, permanent perf tool) #5803

Closed
opened 2026-10-22 04:19:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3111
Author: @kolacheee
Created: 6/30/2026
Status: ✅ Merged
Merged: 6/30/2026
Merged by: @SpicyMarinara

Base: staging ← Head: chore/3104-tracker-perf-diagnostics


📝 Commits (5)

  • 7f0594c chore(client): add temporary render-timing diagnostics for #3104
  • 59e02d4 chore(client): make #3104 render diagnostics verifiable without lag
  • 3b9abb3 chore(client): keep render diagnostics as a permanent opt-in tool
  • 41fd2e0 chore(client): make render diagnostics fully opt-in (off by default)
  • f5986ce Merge branch 'staging' into chore/3104-tracker-perf-diagnostics

📊 Changes

4 files changed (+96 additions, -0 deletions)

View changed files

📝 packages/client/src/App.tsx (+6 -0)
📝 packages/client/src/components/chat/ChatArea.tsx (+2 -0)
📝 packages/client/src/features/tracker-panel/components/TrackerDataSidebar.tsx (+2 -0)
➕ packages/client/src/lib/perf-diagnostics.ts (+86 -0)

📄 Description

Adds a small, fully opt-in render-timing diagnostic to localize client main-thread freezes — motivated by #3104, but designed to stay as a permanent troubleshooting tool for future "the app froze/lagged" reports.

Why

The #3104 freeze (INP ~188s, ~46s synchronous processing, GPU spikes) is a client main-thread block that only manifests on affected users' real chats. It can't be pinned by code reading or local reproduction:

  • The pure-computation layers (tracker sprite-lookup, model builder, macro engine) were measured and are all cheap (ms).
  • A local repro of the tracker panel with synthetic present-characters can't recreate a 46s block (React renders that in ~100ms), so the trigger is something specific to affected users' data that isn't safely synthesizable.

So instead of guessing at a fix, this lets an affected user surface the exact culprit by enabling a flag and reading one console line — and it generalizes to any future client-perf report.

What it does

lib/perf-diagnostics.ts (new) + 3 two-line wire-ins (App.tsx, ChatArea.tsx, TrackerDataSidebar.tsx):

  • useRenderTimer(label) — warns with a component's render+commit duration (ChatArea → "chat-area", TrackerDataSidebar → "tracker-panel").
  • installLongTaskWarner() — warns on main-thread long tasks.

Off by default — completely inert unless enabled. The enable flag is read once at module load, so when it's off there are zero clock reads, zero warnings, no PerformanceObserver, and no console output — it cannot be a source of overhead or lag itself.

  • Enable: localStorage.mariPerfVerbose = "1" in the console, then reload.
  • Disable: localStorage.mariPerfVerbose = "0" (or remove the key), then reload.

When enabled it logs every render + long task; anything ≥250ms is tagged SLOW so the culprit stands out. console.warn is used deliberately (not console.log): production builds strip console.log but keep console.warn, so this surfaces in built installs. Zero behavior change — it only measures and reports.

How to use it (for #3104 and future perf reports)

Tell the affected user: open the laggy chat, open DevTools → Console, run localStorage.mariPerfVerbose = "1", reload, reproduce the freeze, and send the [mari-perf] SLOW … line(s):

[mari-perf] SLOW tracker-panel render+commit 46180ms   ← tracker panel is the cost
[mari-perf] SLOW chat-area render+commit 46180ms        ← the message area / surface is the cost
[mari-perf] SLOW long task 46210ms                       ← (with no matching render) a non-render synchronous block

That names the slow subtree — exactly the info needed to write the targeted fix.

Notes

  • Kept as a permanent opt-in diagnostic (off by default, negligible/zero overhead). Happy to scope it to temporary-and-revert instead if the team prefers — say the word.
  • The longtask PerformanceObserver entry type isn't supported in every browser (guarded; degrades to no-op).
  • Verified end-to-end on a normal install: disabled = no console output; enabled = a one-time "ON" line + per-render numbers; "0"/reload turns it back off.

Test plan (to verify manually)

  • pnpm check passes.
  • Default (no flag): app builds/runs normally with no [mari-perf] console output at all.
  • localStorage.mariPerfVerbose = "1" + reload → one-time [mari-perf] render diagnostics ON … line, then per-render logs (e.g. [mari-perf] chat-area render+commit 7ms).
  • localStorage.mariPerfVerbose = "0" + reload → output stops completely.
  • A chat heavy enough to lag (with the flag on) prints a [mari-perf] SLOW … <N>ms line naming the slow subtree (or a long task).
  • Light and dark mode unaffected (no UI change).

Docs touched

None (internal diagnostic, no user-facing UI/behavior).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3111 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 6/30/2026 **Status:** ✅ Merged **Merged:** 6/30/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `chore/3104-tracker-perf-diagnostics` --- ### 📝 Commits (5) - [`7f0594c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7f0594c6ee9f1ebdcdce19d55cd0bbace02492c0) chore(client): add temporary render-timing diagnostics for #3104 - [`59e02d4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/59e02d4dbc91a21966da3fb214e0337dc69961a3) chore(client): make #3104 render diagnostics verifiable without lag - [`3b9abb3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3b9abb37e90e64a91f055d212414f2399c3a4bbe) chore(client): keep render diagnostics as a permanent opt-in tool - [`41fd2e0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/41fd2e0a91c72a1a74f786cbe4d23cdcd3a35ab6) chore(client): make render diagnostics fully opt-in (off by default) - [`f5986ce`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f5986cec1c1736452be185e4a0c74044839452d1) Merge branch 'staging' into chore/3104-tracker-perf-diagnostics ### 📊 Changes **4 files changed** (+96 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/App.tsx` (+6 -0) 📝 `packages/client/src/components/chat/ChatArea.tsx` (+2 -0) 📝 `packages/client/src/features/tracker-panel/components/TrackerDataSidebar.tsx` (+2 -0) ➕ `packages/client/src/lib/perf-diagnostics.ts` (+86 -0) </details> ### 📄 Description Adds a small, **fully opt-in** render-timing diagnostic to localize client main-thread freezes — motivated by #3104, but designed to **stay** as a permanent troubleshooting tool for future "the app froze/lagged" reports. ## Why The #3104 freeze (INP ~188s, ~46s synchronous processing, GPU spikes) is a **client** main-thread block that only manifests on affected users' real chats. It can't be pinned by code reading or local reproduction: - The pure-computation layers (tracker sprite-lookup, model builder, macro engine) were measured and are all cheap (ms). - A local repro of the tracker panel with synthetic present-characters can't recreate a 46s block (React renders that in ~100ms), so the trigger is something specific to affected users' data that isn't safely synthesizable. So instead of guessing at a fix, this lets an affected user surface the exact culprit by enabling a flag and reading one console line — and it generalizes to any future client-perf report. ## What it does `lib/perf-diagnostics.ts` (new) + 3 two-line wire-ins (`App.tsx`, `ChatArea.tsx`, `TrackerDataSidebar.tsx`): - `useRenderTimer(label)` — warns with a component's render+commit duration (`ChatArea` → `"chat-area"`, `TrackerDataSidebar` → `"tracker-panel"`). - `installLongTaskWarner()` — warns on main-thread long tasks. **Off by default — completely inert unless enabled.** The enable flag is read **once at module load**, so when it's off there are **zero clock reads, zero warnings, no PerformanceObserver, and no console output** — it cannot be a source of overhead or lag itself. - **Enable:** `localStorage.mariPerfVerbose = "1"` in the console, then reload. - **Disable:** `localStorage.mariPerfVerbose = "0"` (or remove the key), then reload. When enabled it logs **every** render + long task; anything ≥250ms is tagged `SLOW` so the culprit stands out. `console.warn` is used deliberately (not `console.log`): production builds strip `console.log` but keep `console.warn`, so this surfaces in built installs. Zero behavior change — it only measures and reports. ## How to use it (for #3104 and future perf reports) Tell the affected user: open the laggy chat, open DevTools → Console, run `localStorage.mariPerfVerbose = "1"`, reload, reproduce the freeze, and send the `[mari-perf] SLOW …` line(s): ``` [mari-perf] SLOW tracker-panel render+commit 46180ms ← tracker panel is the cost [mari-perf] SLOW chat-area render+commit 46180ms ← the message area / surface is the cost [mari-perf] SLOW long task 46210ms ← (with no matching render) a non-render synchronous block ``` That names the slow subtree — exactly the info needed to write the targeted fix. ## Notes - Kept as a **permanent** opt-in diagnostic (off by default, negligible/zero overhead). Happy to scope it to temporary-and-revert instead if the team prefers — say the word. - The `longtask` PerformanceObserver entry type isn't supported in every browser (guarded; degrades to no-op). - Verified end-to-end on a normal install: disabled = no console output; enabled = a one-time "ON" line + per-render numbers; `"0"`/reload turns it back off. ## Test plan (to verify manually) - [ ] `pnpm check` passes. - [ ] Default (no flag): app builds/runs normally with **no** `[mari-perf]` console output at all. - [ ] `localStorage.mariPerfVerbose = "1"` + reload → one-time `[mari-perf] render diagnostics ON …` line, then per-render logs (e.g. `[mari-perf] chat-area render+commit 7ms`). - [ ] `localStorage.mariPerfVerbose = "0"` + reload → output stops completely. - [ ] A chat heavy enough to lag (with the flag on) prints a `[mari-perf] SLOW … <N>ms` line naming the slow subtree (or a long task). - [ ] Light and dark mode unaffected (no UI change). ## Docs touched None (internal diagnostic, no user-facing UI/behavior). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:19:39 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5803
No description provided.