[GH-ISSUE #1582] [Issue]: character list transfers ~300 MB of embedded avatar images on every fetch #820

Closed
opened 2026-10-21 05:21:30 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Gunterlie on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1582

Originally assigned to: @Xelvanis on GitHub.

Summary

Every character list fetch transfers the full base64-encoded avatar image for every character inside the JSON payload. With 182 characters this is a 300 MB transfer taking ~12 seconds before any UI can render. Removing avatarPath from list queries drops the payload to 144 KB and 0.35 seconds — a 2,180× reduction.

Expected behavior

Character pickers and the library open in well under one second. Avatar images load per-card, on demand, only when visible.

Actual behavior

Measured against a live server with 182 characters:

Query Payload Time
Full records (useCharacters) 319 MB 11.9 s
Summary incl. avatarPath (useCharacterSummaries) 315 MB 11.9 s
Summary without avatarPath 144 KB 0.35 s

Per-character breakdown:

avatarPath:   ~1,168,304 bytes  (base64 data URI — the full image)
data.*:             ~629 bytes  (name, tags, extensions)
id + comment:        ~25 bytes

169 of 182 characters store their avatar as data:image/png;base64,... directly in the record. Because avatarPath starts with data:, getCharacterAvatarLoadingMode returns 'eager' — lazy loading provides zero relief.

The field-selection optimization in CHARACTER_SUMMARY_OPTIONS has no effect because avatarPath is one of the selected fields.

Steps to reproduce

  1. Import 150+ characters with avatar images
  2. Open DevTools → Network → filter by invoke
  3. Start a new chat — observe the storage_list POST response is hundreds of MB
  4. Note time from click to list becoming interactive (~12 s on a remote server)

Environment

  • Marinara Engine version: Refactor
  • Install type: MacOS App from Source <---> HTTP Docker Backend on Ubuntu
  • OS + version: macOS (Tauri) + Linux server (Docker/web)

Additional context

Root cause

avatarPath in CHARACTER_SUMMARY_OPTIONS is a precomputed data:image/png;base64,... string, not a file path:

// src/features/catalog/characters/hooks/use-characters.ts
const CHARACTER_SUMMARY_OPTIONS = {
  fields: ["id", "data", "comment", "avatarPath"],  // ← ~1 MB per character
  fieldSelections: { data: ["name", "tags", "extensions"] }
}

The backend already stores the avatar as a file and exposes its path via avatarFilePath and avatarFilename fields (verified in full record responses).

The existing /api/assets/:kind/*path HTTP endpoint serves backgrounds, fonts, and lorebook images but does not yet support avatar as a kind.

Fix (three parts, one PR)

Part A — Remove avatarPath from list queries

const CHARACTER_SUMMARY_OPTIONS = {
  fields: ["id", "data", "comment", "avatarFilename"],  // swap avatarPath → avatarFilename
  fieldSelections: { data: ["name", "tags", "extensions"] }
}

Part B — Add avatar file serving endpoint

Add one match arm to managed_asset_path in src-tauri/src/http_server.rs:

"avatar" => Ok(state.avatars_dir.join(path)),

This exposes /api/assets/avatar/{filename} for remote/web deployments.

Part C — Update CharacterAvatarImage to load from URL

// Remote / web:
const src = `/api/assets/avatar/${avatarFilename}`

// Local Tauri (keeps working unchanged):
const src = convertFileSrc(avatarFilePath)

Because src is now a URL rather than a data URI, the browser uses loading="lazy" — avatars only load when a card scrolls into view.

Constraint: local Tauri install keeps working

convertFileSrc is the standard Tauri utility for turning filesystem paths into webview-loadable URLs. It is already used elsewhere in the codebase. No IPC changes are required.


This is part of a series of related performance issues (#1 of 4).

Related issues: #1583 #1584 #1585

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Gunterlie on GitHub (May 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1582 Originally assigned to: @Xelvanis on GitHub. ## Summary Every character list fetch transfers the full base64-encoded avatar image for every character inside the JSON payload. With 182 characters this is a 300 MB transfer taking ~12 seconds before any UI can render. Removing `avatarPath` from list queries drops the payload to 144 KB and 0.35 seconds — a 2,180× reduction. ## Expected behavior Character pickers and the library open in well under one second. Avatar images load per-card, on demand, only when visible. ## Actual behavior Measured against a live server with 182 characters: | Query | Payload | Time | |---|---|---| | Full records (`useCharacters`) | 319 MB | 11.9 s | | Summary incl. `avatarPath` (`useCharacterSummaries`) | 315 MB | 11.9 s | | Summary without `avatarPath` | **144 KB** | **0.35 s** | Per-character breakdown: ``` avatarPath: ~1,168,304 bytes (base64 data URI — the full image) data.*: ~629 bytes (name, tags, extensions) id + comment: ~25 bytes ``` 169 of 182 characters store their avatar as `data:image/png;base64,...` directly in the record. Because `avatarPath` starts with `data:`, `getCharacterAvatarLoadingMode` returns `'eager'` — lazy loading provides zero relief. The field-selection optimization in `CHARACTER_SUMMARY_OPTIONS` has no effect because `avatarPath` is one of the selected fields. ## Steps to reproduce 1. Import 150+ characters with avatar images 2. Open DevTools → Network → filter by `invoke` 3. Start a new chat — observe the `storage_list` POST response is hundreds of MB 4. Note time from click to list becoming interactive (~12 s on a remote server) ## Environment - Marinara Engine version: Refactor - Install type: MacOS App from Source <---> HTTP Docker Backend on Ubuntu - OS + version: macOS (Tauri) + Linux server (Docker/web) ## Additional context ### Root cause `avatarPath` in `CHARACTER_SUMMARY_OPTIONS` is a precomputed `data:image/png;base64,...` string, not a file path: ```ts // src/features/catalog/characters/hooks/use-characters.ts const CHARACTER_SUMMARY_OPTIONS = { fields: ["id", "data", "comment", "avatarPath"], // ← ~1 MB per character fieldSelections: { data: ["name", "tags", "extensions"] } } ``` The backend already stores the avatar as a file and exposes its path via `avatarFilePath` and `avatarFilename` fields (verified in full record responses). The existing `/api/assets/:kind/*path` HTTP endpoint serves backgrounds, fonts, and lorebook images but does not yet support `avatar` as a kind. ### Fix (three parts, one PR) **Part A — Remove `avatarPath` from list queries** ```ts const CHARACTER_SUMMARY_OPTIONS = { fields: ["id", "data", "comment", "avatarFilename"], // swap avatarPath → avatarFilename fieldSelections: { data: ["name", "tags", "extensions"] } } ``` **Part B — Add avatar file serving endpoint** Add one match arm to `managed_asset_path` in `src-tauri/src/http_server.rs`: ```rust "avatar" => Ok(state.avatars_dir.join(path)), ``` This exposes `/api/assets/avatar/{filename}` for remote/web deployments. **Part C — Update `CharacterAvatarImage` to load from URL** ```ts // Remote / web: const src = `/api/assets/avatar/${avatarFilename}` // Local Tauri (keeps working unchanged): const src = convertFileSrc(avatarFilePath) ``` Because `src` is now a URL rather than a data URI, the browser uses `loading="lazy"` — avatars only load when a card scrolls into view. ### Constraint: local Tauri install keeps working `convertFileSrc` is the standard Tauri utility for turning filesystem paths into webview-loadable URLs. It is already used elsewhere in the codebase. No IPC changes are required. --- > This is part of a series of related performance issues (#1 of 4). > > **Related issues:** #1583 #1584 #1585 ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:21:30 +07:00
Author
Owner

@Xelvanis commented on GitHub (May 29, 2026):

Checked #1590 against this issue. It looks like #1590 is a partial fix, not a complete resolution of #1582 as written.

What #1590 fixed:

  • useCharacterSummaries no longer selects embedded avatarPath; it now selects avatarFilePath and avatarFilename.
  • The hostable /api/assets/avatar/... route and shared avatar URL helper were added for remote avatar serving.
  • Sidebar/lorebook/setup consumers moved to summary-style reads should avoid carrying embedded avatar image data in those list payloads.

Remaining gap:

  • useCharacters() still calls storageApi.list("characters") with no projection in src/features/catalog/characters/hooks/use-characters.ts, so it still fetches full character records.
  • CharacterLibraryView and CharactersPanel still call useCharacters() on load, so the library/panel paths can still transfer full embedded base64 avatarPath data for large libraries.
  • A few other internal consumers still use the full character list too. Some may legitimately need full card data, but this keeps the issue from being fully resolved under the original report.

Also noting the GitHub closure state: #1590 merged into refactor while the repo default branch is main, so GitHub did not auto-close this issue from the Closes #1582 text. The issue is still open and closingIssuesReferences is empty.

Recommendation: keep this issue open until the character library/panel list paths stop using unprojected full-character reads, or narrow this issue to only the summary/sidebar/lorebook portion and track the remaining useCharacters() payload work separately.

<!-- gh-comment-id:4578431565 --> @Xelvanis commented on GitHub (May 29, 2026): Checked #1590 against this issue. It looks like #1590 is a partial fix, not a complete resolution of #1582 as written. What #1590 fixed: - `useCharacterSummaries` no longer selects embedded `avatarPath`; it now selects `avatarFilePath` and `avatarFilename`. - The hostable `/api/assets/avatar/...` route and shared avatar URL helper were added for remote avatar serving. - Sidebar/lorebook/setup consumers moved to summary-style reads should avoid carrying embedded avatar image data in those list payloads. Remaining gap: - `useCharacters()` still calls `storageApi.list("characters")` with no projection in `src/features/catalog/characters/hooks/use-characters.ts`, so it still fetches full character records. - `CharacterLibraryView` and `CharactersPanel` still call `useCharacters()` on load, so the library/panel paths can still transfer full embedded base64 `avatarPath` data for large libraries. - A few other internal consumers still use the full character list too. Some may legitimately need full card data, but this keeps the issue from being fully resolved under the original report. Also noting the GitHub closure state: #1590 merged into `refactor` while the repo default branch is `main`, so GitHub did not auto-close this issue from the `Closes #1582` text. The issue is still open and `closingIssuesReferences` is empty. Recommendation: keep this issue open until the character library/panel list paths stop using unprojected full-character reads, or narrow this issue to only the summary/sidebar/lorebook portion and track the remaining `useCharacters()` payload work separately.
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#820
No description provided.