mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #1580] [Issue]: character list loading transfers ~300 MB of embedded avatar images on every fetch — slow at 180 characters, unusable at scale #818
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#818
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 @Gunterlie on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1580
Big one, should really be multiple Issues. But I think important for long time stability.
Summary
Every character list fetch — triggered by pickers, the library view, the sidebar, and lorebook editors — transfers the full base64-encoded avatar image for every character inside the JSON payload. With 182 characters, this is a 300 MB transfer that takes ~12 seconds ON LOCAL CONNECTION! before any UI can render. The field-selection optimization in
CHARACTER_SUMMARY_OPTIONShas no effect becauseavatarPath(the embedded data URI) is included in the summary. RemovingavatarPathfrom list queries drops the payload to 144 KB and 0.35 seconds — a 2,180× reduction.Expected behavior
Character pickers, the library grid, and the sidebar open in well under one second regardless of collection size. Avatar images load per-card, on demand, only when visible.
Actual behavior
Measured against a live server with 182 characters:
storage_listwith full records (useCharacters)storage_listwith summary fields incl.avatarPath(useCharacterSummaries)storage_listwithoutavatarPathThe summary fetch is almost identical in size to the full fetch because
avatarPathdominates: 300.7 MB of the 315 MB summary payload is base64-encoded avatar images (169 of 182 characters store their avatar as adata:image/png;base64,...URI directly in the record).Per-character breakdown for a single record:
Because
avatarPathvalues that start withdata:are loaded withloading="eager"(seegetCharacterAvatarLoadingMode), lazy-loading provides no relief either — every avatar in the payload renders immediately.Steps to reproduce
storage_listresponse that is hundreds of MBEnvironment
Additional context
Root cause
The
avatarPathfield in a character record is not a filesystem path or URL — it is a precomputeddata:image/png;base64,...string that encodes the full avatar image. This field is included inCHARACTER_SUMMARY_OPTIONS(the field selection used byuseCharacterSummaries), which means every list fetch downloads every avatar image in full resolution as part of the JSON body.The backend already stores the avatar as a file and tracks its path via a separate
avatarFilePathfield (verified in the full record response). An HTTP asset endpoint already exists at/api/assets/:kind/*pathbut does not currently supportavataras a kind.Secondary issues (smaller but real)
These compound the main problem and should be addressed in the same pass:
1. No DOM virtualization
CharacterLibraryView.tsx(line 400) andCharactersPanel.tsx(line 115) map all filtered characters directly to DOM nodes with no windowing. At 200 characters, 200 full card elements exist in the DOM simultaneously.@tanstack/react-virtualis not installed.2. Full records fetched for list views
CharacterLibraryViewandCharactersPanelcalluseCharacters()(query key["characters","list"], no field projection) instead ofuseCharacterSummaries(). This fetchesdescription,personality,scenario,first_mes, andalternate_greetingsthat are not displayed in a list card. With the avatar fix in place, this adds ~10 KB per character unnecessarily.3. No backend search
The Rust entity list handler (
src-tauri/src/commands/storage/commands/entities.rsline 61) supports only exact-matchfiltersvialist_where. All name/tag/creator search is done client-side viaArray.filter()after downloading the full dataset. This means the full payload must land before the user can type.4. Two separate unbounded fetches can be active simultaneously
useCharacters()(key["characters","list"]) anduseCharacterSummaries()(key["characters","summaries"]) are separate React Query cache entries. React Query correctly deduplicates within each key, but when the library view and a picker are open at the same time, both fetches fire independently — doubling the transfer.Proposed fix
Step 1 — Remove
avatarPathfrom all list queries (99.5% payload reduction, no architectural changes needed)Remove
avatarPathfromCHARACTER_SUMMARY_OPTIONS. Replace it withavatarFilename(already present in the record, 42 bytes).This alone drops the 315 MB summary payload to ~144 KB and load time from ~12 s to ~0.35 s.
Step 2 — Add avatar file serving endpoint
Add
"avatar"to themanaged_asset_pathmatch inhttp_server.rs:This exposes
/api/assets/avatar/{filename}as a proper HTTP endpoint, compatible with remote deployments.Step 3 — Load avatars per card, lazily, using the filename
In
CharacterAvatarImage(or the hook that feeds it), construct the avatar URL:/api/assets/avatar/{avatarFilename}convertFileSrc(avatarFilePath)(Tauri's existing utility for converting filesystem paths to webview-loadable URLs — no change to the local install path)Because the
srcis now a URL (not a data URI), the browser usesloading="lazy"— avatars genuinely only load when the card scrolls into view. Both install modes continue to work.Step 4 — Add DOM virtualization (frontend only, no backend changes)
Install
@tanstack/react-virtualand virtualizeCharacterLibraryViewandCharactersPanel. With Step 1 done, the list data lands in ~350ms; virtualization then ensures only ~30 DOM nodes exist regardless of collection size.Step 5 — Switch library/panel from
useCharacters()touseCharacterSummaries()CharacterLibraryView.tsx:201andCharactersPanel.tsx:115useuseCharacters()which fetches the full record. After Step 1 the summary is lean enough that the library can use it — full records are only needed in the character detail/editor view.Step 6 — Backend substring search (enables true search-as-you-type)
Add a
searchparameter to the Rust entity list handler. A SQLiteLIKE '%term%'on the name field is sufficient for <10k records. The React Query key includes the search term, so each distinct query has its own cache entry. This removes the requirement to download the full dataset before the user can search.Constraint: local Tauri install must keep working
Every change above is backward-compatible and transport-agnostic:
storageApi/invokeabstraction — no HTTP-only assumptionsconvertFileSrcis the standard Tauri utility for filesystem paths in the webview; it is already used elsewhere in the codebasesearch) are additive and optional; callers that omit them get current behavior/api/assets/avatar/endpoint is additive; nothing is removedQuick wins (can ship in one PR, zero backend changes)
These four changes alone make the app dramatically faster and carry no risk:
avatarPathfromCHARACTER_SUMMARY_OPTIONS— 315 MB → 144 KB, 12 s → 0.35 sCharacterLibraryView+CharactersPaneltouseCharacterSummaries()— eliminates the second unbounded full-record fetch@tanstack/react-virtualto both list views — fixes DOM bloatChatSidebar: replaceuseCharacterSummaries()withuseCharacterSummariesByIds(activeIds)— the sidebar only needs avatars/names for characters in active chats, not the entire libraryItems 2 and 3 in the avatar endpoint (Steps 2–3 above) are required to make the list display avatars again after removing
avatarPath— they should ship in the same PR as quick win #1.Template check
@Gunterlie commented on GitHub (May 29, 2026):
Will split issues