[PR #7444] [MERGED] perf(server): send JSON bodies above 4 MB uncompressed #7738

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7444
Author: @SpicyMarinara
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/11/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/compress-json-cap


📝 Commits (1)

  • 50477ac perf(server): send JSON bodies above 4 MB uncompressed

📊 Changes

2 files changed (+14 additions, -1 deletions)

View changed files

📝 packages/server/src/middleware/compress-json.ts (+8 -1)
📝 scripts/regressions/compress-json.regression.ts (+6 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7440 (follow-up to #7441)

Why this change

  • #7441 made JSON compression synchronous to fix empty Game setup replies. A real-HTTP review then measured the cost: about 7 ms/MB for brotli q4 and 11–13 ms/MB for gzip 6 on an Apple M4. That is 10–20× JSON.stringify, not the "1–6 ms/MB" #7441 claimed.
  • Measured on a 12,000-message chat: its full message list (12 MB, fetched by in-chat search, rolling-summary backfill and Game replay) paused every concurrent request for 110–160 ms. Over plain-HTTP LAN, browsers usually offer only gzip, which is the slower case. Phones and small hosts hit the same pause at a few MB.
  • Local CodeRabbit on #7441 asked for exactly this cap, twice.

What changed

  • compressJsonHook skips compression for bodies above 4 MB, which then go out as they did before compression existed. The worst main-thread cost is about 30–50 ms.
  • A ponytail: comment records the ceiling and the upgrade path: return every reply.send in async handlers, then compress large bodies on the threadpool again.
  • Regression: compress-json checks that a body just over 4 MB stays uncompressed and intact. It fails without the cap.
  • No CHANGELOG entry. Compression hasn't been released yet, and nothing changes for users except fewer pauses.

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

Commands run by the agent: pnpm check, node ./scripts/run-regressions.mjs --filter scripts/regressions/compress-json.regression.ts (passes, and fails with the cap removed).

Manual verification notes

  • Manually verify that a normal chat's message list is still compressed (DevTools Network shows content-encoding: br).
  • Manually verify that a very long chat's full message list loads uncompressed, with no visible pause in other open tabs.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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)

Summary by CodeRabbit

  • Bug Fixes
    • JSON responses larger than 4 MiB are now sent uncompressed, while smaller eligible responses remain compressible.

🔄 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/7444 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/11/2026 **Status:** ✅ Merged **Merged:** 10/11/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/compress-json-cap` --- ### 📝 Commits (1) - [`50477ac`](https://github.com/Pasta-Devs/Marinara-Engine/commit/50477acc5ee51f1d6e61efe5e981fb6b5bb603d4) perf(server): send JSON bodies above 4 MB uncompressed ### 📊 Changes **2 files changed** (+14 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/middleware/compress-json.ts` (+8 -1) 📝 `scripts/regressions/compress-json.regression.ts` (+6 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7440 (follow-up to #7441) ## Why this change - #7441 made JSON compression synchronous to fix empty Game setup replies. A real-HTTP review then measured the cost: about 7 ms/MB for brotli q4 and 11–13 ms/MB for gzip 6 on an Apple M4. That is 10–20× `JSON.stringify`, not the "1–6 ms/MB" #7441 claimed. - Measured on a 12,000-message chat: its full message list (12 MB, fetched by in-chat search, rolling-summary backfill and Game replay) paused every concurrent request for 110–160 ms. Over plain-HTTP LAN, browsers usually offer only gzip, which is the slower case. Phones and small hosts hit the same pause at a few MB. - Local CodeRabbit on #7441 asked for exactly this cap, twice. ## What changed - `compressJsonHook` skips compression for bodies above 4 MB, which then go out as they did before compression existed. The worst main-thread cost is about 30–50 ms. - A `ponytail:` comment records the ceiling and the upgrade path: return every `reply.send` in async handlers, then compress large bodies on the threadpool again. - Regression: `compress-json` checks that a body just over 4 MB stays uncompressed and intact. It fails without the cap. - No CHANGELOG entry. Compression hasn't been released yet, and nothing changes for users except fewer pauses. ## 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` Commands run by the agent: `pnpm check`, `node ./scripts/run-regressions.mjs --filter scripts/regressions/compress-json.regression.ts` (passes, and fails with the cap removed). ### Manual verification notes - Manually verify that a normal chat's message list is still compressed (DevTools Network shows `content-encoding: br`). - Manually verify that a very long chat's full message list loads uncompressed, with no visible pause in other open tabs. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * JSON responses larger than 4 MiB are now sent uncompressed, while smaller eligible responses remain compressible. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:00 +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#7738
No description provided.