[PR #2504] [MERGED] Speed up chat message storage appends #5625

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2504
Author: @Xelvanis
Created: 6/6/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Xelvanis

Base: refactor ← Head: perf/issue-2493-app-speed


📝 Commits (2)

  • d73bcc1 Speed up chat message storage appends
  • bddd27b Preserve explicit message replacement writes

📊 Changes

2 files changed (+718 additions, -30 deletions)

View changed files

📝 src-tauri/crates/storage/src/lib.rs (+410 -1)
📝 src-tauri/src/commands/storage/message_swipes.rs (+308 -29)

📄 Description

Linked issue

Related to #2493

Why this change

  • Large chats were paying full collection load/rewrite costs when creating new chat messages and initial swipe sidecars. Startup migrations can also warm clean messages and message-swipes caches, which made the append fast path unreachable unless the collections were completely uncached.

What changed

  • Added a transactional append path for multiple uncached storage collections so new message creation can append messages and message-swipes rows together instead of rewriting both full collections.
  • Allowed the append path to proceed when collections are clean-cached, updating those caches after a successful disk append while still refusing dirty cached collections and falling back to the existing full rewrite path.
  • Wired chat message creation with initial swipe sidecars through the append fast path, with fallback to the existing atomic replacement path.
  • Hardened append staging cleanup so preparation errors remove previously created transaction temp files.

Refactor impact

Primary owner:

Rust storage

Impact areas reviewed:

  • src-tauri/crates/storage/src/lib.rs collection append, cache, temp-file rollback, and dirty-cache behavior.
  • src-tauri/src/commands/storage/message_swipes.rs create-message sidecar persistence.
  • Startup-warmed messages / message-swipes cache behavior.
  • Message swipe sidecar tests covering create, materialization, migration, delete, inactive swipes, and extra preservation.

Boundary notes:

  • The change stays in Rust storage/Tauri command ownership.
  • No React feature, TypeScript engine, shared API, or remote-runtime dispatch changes.
  • The fast path falls back to the existing full atomic rewrite path when dirty cached collections or unsafe append conditions are detected.

Pressure points touched:

  • Rust storage crate collection persistence.
  • Storage message swipe command helper.
  • No ModeSurface, GameSurface, command registration, or import modules touched.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

Commands run locally:

  • cargo fmt --manifest-path src-tauri/crates/storage/Cargo.toml -- --check
  • git diff --check
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage append_many_uncached
  • cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine message_swipes --lib
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace
  • pnpm check

Manual/native Tauri timing proof was not run yet. Follow-up should compare send and regenerate timings on a large chat.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • Internal Rust storage performance fix only; no user-facing feature or workflow is added.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

No visible UI changes. Runtime timing proof remains follow-up work for large-chat performance measurement.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added optimized batch append operation for multiple data collections.
  • Refactor

    • Improved performance for newly created message persistence with swipe variants.
  • Tests

    • Added comprehensive test coverage for new batch append operations.

🔄 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/2504 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/6/2026 **Status:** ✅ Merged **Merged:** 6/6/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `perf/issue-2493-app-speed` --- ### 📝 Commits (2) - [`d73bcc1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d73bcc1b8be1ab66872bfa1a2799dae278037c7c) Speed up chat message storage appends - [`bddd27b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bddd27ba86bf0031fc08dd8e08371916f64e6a40) Preserve explicit message replacement writes ### 📊 Changes **2 files changed** (+718 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/storage/src/lib.rs` (+410 -1) 📝 `src-tauri/src/commands/storage/message_swipes.rs` (+308 -29) </details> ### 📄 Description ## Linked issue Related to #2493 ## Why this change - Large chats were paying full collection load/rewrite costs when creating new chat messages and initial swipe sidecars. Startup migrations can also warm clean `messages` and `message-swipes` caches, which made the append fast path unreachable unless the collections were completely uncached. ## What changed - Added a transactional append path for multiple uncached storage collections so new message creation can append `messages` and `message-swipes` rows together instead of rewriting both full collections. - Allowed the append path to proceed when collections are clean-cached, updating those caches after a successful disk append while still refusing dirty cached collections and falling back to the existing full rewrite path. - Wired chat message creation with initial swipe sidecars through the append fast path, with fallback to the existing atomic replacement path. - Hardened append staging cleanup so preparation errors remove previously created transaction temp files. ## Refactor impact Primary owner: Rust storage Impact areas reviewed: - `src-tauri/crates/storage/src/lib.rs` collection append, cache, temp-file rollback, and dirty-cache behavior. - `src-tauri/src/commands/storage/message_swipes.rs` create-message sidecar persistence. - Startup-warmed `messages` / `message-swipes` cache behavior. - Message swipe sidecar tests covering create, materialization, migration, delete, inactive swipes, and extra preservation. Boundary notes: - The change stays in Rust storage/Tauri command ownership. - No React feature, TypeScript engine, shared API, or remote-runtime dispatch changes. - The fast path falls back to the existing full atomic rewrite path when dirty cached collections or unsafe append conditions are detected. Pressure points touched: - Rust storage crate collection persistence. - Storage message swipe command helper. - No `ModeSurface`, `GameSurface`, command registration, or import modules touched. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes Commands run locally: - `cargo fmt --manifest-path src-tauri/crates/storage/Cargo.toml -- --check` - `git diff --check` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-storage append_many_uncached` - `cargo test --manifest-path src-tauri/Cargo.toml -p marinara-engine message_swipes --lib` - `cargo check --manifest-path src-tauri/Cargo.toml --workspace` - `pnpm check` Manual/native Tauri timing proof was not run yet. Follow-up should compare send and regenerate timings on a large chat. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - Internal Rust storage performance fix only; no user-facing feature or workflow is added. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence No visible UI changes. Runtime timing proof remains follow-up work for large-chat performance measurement. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added optimized batch append operation for multiple data collections. * **Refactor** * Improved performance for newly created message persistence with swipe variants. * **Tests** * Added comprehensive test coverage for new batch append operations. <!-- 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-22 04:17:55 +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#5625
No description provided.