mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2301] [Issue]: Every message create/edit/swipe deep-clones and deep-compares the entire global messages + message-swipes collections #1135
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1135
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2301
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: High — Performance. Every message mutation (create, edit, add/switch/delete swipe, branch copy) routes through
write_message_and_swipes -> Storage::update_collections_atomically, which reads, deep-clones, and deep-compares the entire globalmessagesandmessage-swipescollections. Cost scales with the total number of messages/swipes across every chat, not the active chat, and runs under the storage write lock on every turn.Expected behavior
A single message create/edit/swipe should cost work proportional to the active chat (or to the changed rows), not to the entire message corpus. The conflict check in particular should not deep-compare the whole collection.
Actual behavior
update_collections_atomically(src-tauri/crates/storage/src/lib.rs:604-663), invoked for["messages", "message-swipes"]bywrite_message_and_swipes(commands/storage/message_swipes.rs:359-390), performs, per single mutation, over the global collections (N = all messages, M = all swipes), all under the write lock:read_collection_no_recoveryreturnscached.rows.clone()— full deep-clone of N (+M). A cache hit does not avoid the clone (cached_rows,lib.rs:730-740, always.clone()s the whole Vec).entry.rows.clone()intooriginal_rows— deep-clone #2.read_collection_no_recovery(collection)? != *rows— deep-clone #3 plus a fullserde_json::Valuestructural deep-equality over the entire N (+M):entry.rows.clone()intoreplacements— deep-clone #4.replace_all_many_locked(lib.rs:1902) —serde_json::to_vec_pretty(rows)full re-serialize of both collections.So roughly 4 full deep-clones + 1 full deep-equality + 1 full serialize of the entire global messages collection and the entire swipes collection, per mutation.
Hot path confirmed:
create_message(message_swipes.rs:831/841/846),set_active_swipe, patch/edit (874), branch copy (911), and deletes (759/798) all route throughwrite_message_and_swipes.messages/message-swipesare single global collections (one in-memoryVec<Value>across all chats; rows carry achatIdonly for in-memory filtering) — there is no per-chat sharding, so cost scales with the total corpus. The append fast-path increate_locked(lib.rs:344-351) is dead for message creation:create_messagenever callscreate_locked, and after the first chat load the collection is already cached.Steps to reproduce
Impact area
Environment
47b16701Logs, screenshots, or video
Static source audit; claims cited to file:line above.
Regression notes
Found via static audit of the refactor branch; not verified against main.
Additional context
Two fix directions:
read_collection_no_recovery != original_rowsdeep-equality with the already-computedCollectionFileStamp.content_signature(a version/stamp guard), eliminating the most wasteful step without changing the storage format.chatIdso reads/writes/compares scale with the active chat. Larger change, addresses the clone cost as well.Template check
Please uncheck the box below before submitting so we know you read the template. It is intentionally pre-checked:
@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2399, merged into
refactor.