[PR #8052] [MERGED] perf(game): stop reprocessing the whole history on every step #8075

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8052
Author: @kolacheee
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @kolacheee

Base: staging ← Head: claude/project-thread-23tuwp


📝 Commits (6)

  • 5a75f87 perf(game): stop reprocessing the whole history on every step
  • df2e4c4 test(game): use an over-long pattern for the refused-pattern check
  • 358aafd style: format the session log memo regression
  • 1fc23c5 Merge remote-tracking branch 'origin/staging' into claude/project-thread-23tuwp
  • fde3835 Merge remote-tracking branch 'origin/staging' into claude/project-thread-23tuwp
  • 931f67a Merge remote-tracking branch 'origin/staging' into claude/project-thread-23tuwp

📊 Changes

7 files changed (+435 additions, -103 deletions)

View changed files

📝 e2e/game-log-page.e2e.ts (+52 -0)
📝 packages/client/src/components/game/GameNarration.tsx (+185 -96)
📝 packages/client/src/components/game/GameSurface.tsx (+30 -4)
➕ packages/client/src/components/game/message-memo.ts (+44 -0)
📝 packages/client/src/hooks/use-apply-regex.ts (+36 -3)
➕ scripts/regressions/game-session-log-memo.regression.ts (+87 -0)
📝 scripts/regressions/tsconfig.client-lanes.json (+1 -0)

📄 Description

Linked issue

Closes #8051

Why this change

  • In a long game, every skip, reveal, send, log jump and chat-settings toggle redid work across every loaded message, even with the Session Log closed. Each message was parsed again, and each line went back through macros and every display regex script, with each pattern checked and compiled again. #8031 limited how many log rows are drawn, but this pass still ran before them. With dozens of display regex scripts and Messages per page at 0, a tap took close to half a second on a phone.

What changed

  • Game Mode responds faster in long games. Skipping, revealing, jumping from the Session Log and toggling chat settings no longer reprocess every earlier message.
  • Display regex scripts are checked and compiled once per pattern instead of once per line, so large script collections cost much less.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Timed production builds with a 250-message game (3 characters with sprites), 30 display regex scripts and Messages per page at 0, on a Pixel 7 viewport at 4x CPU throttle, using Event Timing for each tap. Next went from a median of 424 ms to 160 ms. A log jump went from 504 ms to 232 ms. Opening the log stays around 400 ms, and a profile shows that time is now spent drawing its 20 rows.
  • How it works:
    • Past log entries, review entries and translation sources are kept per message. A message is rebuilt only when one of its fields changes, or when something every message depends on changes: speaker colors, edit or delete overlays, the persona, the language, or the regex scripts.
    • The current scene and the live party chat are still built on every step.
    • When an enabled script has a depth range, a new message rebuilds the older ones as before, because their depth moved.
  • Point 4 of the report (memoizing GameNarration) is left out. GameSurface passes new slot elements and inline callbacks on every render, so React.memo would never skip a render. Making each render cheap fixes the same lag.
  • New e2e test in e2e/game-log-page.e2e.ts:
    • It checks that an edit to an older log line shows right away and after reopening the log, and that a depth-limited regex script changes only the newest turn.
    • It fails when the log cache ignores the edit overlays.
  • New regression game-session-log-memo covers when the per-message memo reuses or rebuilds an entry, and the shared compiled patterns.
  • Related e2e tests pass on desktop-chromium: game-log-page, game-log-overflow, game-turn-macros, game-native-dice, game-one-request-dice, game-verb-only-turn, game-ruleset-item-use-outside, preset-regex and markdown-blocks.
  • Client tsc --noEmit, the client regression lane tsconfig, ESLint and Prettier are clean on the changed files.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

  • No visual change.

🔄 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/8052 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `claude/project-thread-23tuwp` --- ### 📝 Commits (6) - [`5a75f87`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5a75f8706f24268232a599661e4f4f48510b65a0) perf(game): stop reprocessing the whole history on every step - [`df2e4c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df2e4c4627e2a421f5b5dc9b7a872dc0a2a84777) test(game): use an over-long pattern for the refused-pattern check - [`358aafd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/358aafd8c9e6453600823b63a73c9d3b76b041af) style: format the session log memo regression - [`1fc23c5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1fc23c561e4c1cf7bac43b0a04debf09b2551c48) Merge remote-tracking branch 'origin/staging' into claude/project-thread-23tuwp - [`fde3835`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fde3835edcc0785c2c1ba43aa6b46b3c5a51564a) Merge remote-tracking branch 'origin/staging' into claude/project-thread-23tuwp - [`931f67a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/931f67a8613c28949fac0689fb23d6206d341fe0) Merge remote-tracking branch 'origin/staging' into claude/project-thread-23tuwp ### 📊 Changes **7 files changed** (+435 additions, -103 deletions) <details> <summary>View changed files</summary> 📝 `e2e/game-log-page.e2e.ts` (+52 -0) 📝 `packages/client/src/components/game/GameNarration.tsx` (+185 -96) 📝 `packages/client/src/components/game/GameSurface.tsx` (+30 -4) ➕ `packages/client/src/components/game/message-memo.ts` (+44 -0) 📝 `packages/client/src/hooks/use-apply-regex.ts` (+36 -3) ➕ `scripts/regressions/game-session-log-memo.regression.ts` (+87 -0) 📝 `scripts/regressions/tsconfig.client-lanes.json` (+1 -0) </details> ### 📄 Description ## Linked issue Closes #8051 ## Why this change - In a long game, every skip, reveal, send, log jump and chat-settings toggle redid work across every loaded message, even with the Session Log closed. Each message was parsed again, and each line went back through macros and every display regex script, with each pattern checked and compiled again. #8031 limited how many log rows are drawn, but this pass still ran before them. With dozens of display regex scripts and Messages per page at 0, a tap took close to half a second on a phone. ## What changed - Game Mode responds faster in long games. Skipping, revealing, jumping from the Session Log and toggling chat settings no longer reprocess every earlier message. - Display regex scripts are checked and compiled once per pattern instead of once per line, so large script collections cost much less. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Timed production builds with a 250-message game (3 characters with sprites), 30 display regex scripts and Messages per page at 0, on a Pixel 7 viewport at 4x CPU throttle, using Event Timing for each tap. Next went from a median of 424 ms to 160 ms. A log jump went from 504 ms to 232 ms. Opening the log stays around 400 ms, and a profile shows that time is now spent drawing its 20 rows. - How it works: - Past log entries, review entries and translation sources are kept per message. A message is rebuilt only when one of its fields changes, or when something every message depends on changes: speaker colors, edit or delete overlays, the persona, the language, or the regex scripts. - The current scene and the live party chat are still built on every step. - When an enabled script has a depth range, a new message rebuilds the older ones as before, because their depth moved. - Point 4 of the report (memoizing `GameNarration`) is left out. `GameSurface` passes new slot elements and inline callbacks on every render, so `React.memo` would never skip a render. Making each render cheap fixes the same lag. - New e2e test in `e2e/game-log-page.e2e.ts`: - It checks that an edit to an older log line shows right away and after reopening the log, and that a depth-limited regex script changes only the newest turn. - It fails when the log cache ignores the edit overlays. - New regression `game-session-log-memo` covers when the per-message memo reuses or rebuilds an entry, and the shared compiled patterns. - Related e2e tests pass on desktop-chromium: `game-log-page`, `game-log-overflow`, `game-turn-macros`, `game-native-dice`, `game-one-request-dice`, `game-verb-only-turn`, `game-ruleset-item-use-outside`, `preset-regex` and `markdown-blocks`. - Client `tsc --noEmit`, the client regression lane tsconfig, ESLint and Prettier are clean on the changed files. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) - No visual change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:10:10 +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#8075
No description provided.