[GH-ISSUE #1185] Bulk sprite folder imports are slow due to per-file base64 upload and repeated list refresh #585

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

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

Originally assigned to: @cha1latte on GitHub.

Summary

Bulk folder uploads for character/persona sprites are much slower than expected for larger sprite folders. The current flow processes one file at a time through browser base64 + Tauri IPC, then invalidates/refetches the full sprite list after every uploaded file.

Current behavior

  • Upload Folder in the character sprite tab and persona sprite tab loops through selected images sequentially.
  • Each file is read in the webview with FileReader.readAsDataURL, then sent through sprite_upload as a base64 data URL.
  • useUploadSprite invalidates spriteKeys.list(characterId) after each successful upload.
  • sprite_list reads every sprite file in the folder and returns every image as a base64 data URL.
  • sprite_upload also decodes the incoming base64, writes the file, then reads and base64-encodes the saved file for the response.

This makes a folder import with N images trend toward repeated full-library work: upload one sprite, re-list/re-encode the growing sprite folder, upload the next sprite, repeat.

Expected behavior

Bulk sprite folder import should import many files with progress, update the query/cache once or in controlled batches, and avoid re-reading/re-encoding the entire sprite library for every file.

Evidence / code paths

  • src/features/catalog/characters/components/CharacterEditor.tsx - handleFolderUpload
  • src/features/catalog/personas/components/PersonaEditor.tsx - handleFolderUpload
  • src/shared/hooks/use-sprites.ts - useUploadSprite invalidates the sprite list on every upload success
  • src/shared/api/image-generation-api.ts - spriteApi.list / spriteApi.upload
  • src-tauri/src/commands/storage/commands/media.rs - sprite_list / sprite_upload commands
  • src-tauri/src/commands/storage/sprites.rs - list_sprites, upload_sprite, and sprite_info_from_path

Likely bottlenecks

  • Browser reads each image into base64 before upload.
  • One Tauri invoke per sprite.
  • Rust decodes base64, writes bytes, then reads and re-encodes the written file for the response.
  • React Query invalidates/refetches the complete sprite list after each individual upload.
  • sprite_list returns full base64 data URLs for every sprite, so every refresh scales with total sprite bytes.

Existing better pattern nearby

SillyTavern bulk import already uses a native folder/path-token style flow with Rust-side scanning/copying and progress events:

  • src-tauri/src/commands/storage/imports/access.rs
  • src-tauri/src/commands/storage/imports/bulk_imports.rs
  • src/shared/api/import-api.ts

Sprite folder import would likely benefit from a similar native bulk command/event path instead of routing every image through browser base64 IPC.

Proposed direction

  1. Add a bulk sprite import API/command, such as sprite_upload_bulk for batched web uploads and/or sprite_import_folder_events for native folder imports.
  2. For native Tauri, prefer Rust-side folder import after a folder picker selection so the app can copy/read files directly and stream progress.
  3. Keep a web fallback that sends an array of upload payloads in one command when native folder access is unavailable.
  4. Invalidate spriteKeys.list(characterId) once after the bulk import completes, not once per file.
  5. Return a bulk result with { imported, failed, sprites? } or progress events, including filenames/errors instead of silently swallowing failures.
  6. Consider changing sprite_list to return metadata plus managed/local asset URLs instead of base64 image data. This is the bigger contract change but would improve editor load, roleplay overlays, game sprite lookup, tracker portraits, and slash-command sprite listing.

Verification plan

  • Import sprite folders with roughly 10, 50, and 100+ images for both characters and personas.
  • Test both facial-expression and full-body sprite categories.
  • Confirm existing replacement/name normalization behavior, including full_ prefix handling.
  • Confirm failures are reported without aborting the entire import.
  • Check runtime consumers after import: character editor grid, persona editor grid, roleplay sprite overlay, expression panel/sidebar, game sprite lookup, tracker portrait sprites, and slash-command sprite listing.
  • Run pnpm typecheck, cargo check --manifest-path src-tauri/Cargo.toml, and pnpm check:architecture for the implementation.

Notes

This issue is based on code-path investigation. It still needs runtime timing measurements before/after implementation to quantify the improvement.

Originally created by @Xelvanis on GitHub (May 25, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1185 Originally assigned to: @cha1latte on GitHub. ## Summary Bulk folder uploads for character/persona sprites are much slower than expected for larger sprite folders. The current flow processes one file at a time through browser base64 + Tauri IPC, then invalidates/refetches the full sprite list after every uploaded file. ## Current behavior - `Upload Folder` in the character sprite tab and persona sprite tab loops through selected images sequentially. - Each file is read in the webview with `FileReader.readAsDataURL`, then sent through `sprite_upload` as a base64 data URL. - `useUploadSprite` invalidates `spriteKeys.list(characterId)` after each successful upload. - `sprite_list` reads every sprite file in the folder and returns every image as a base64 data URL. - `sprite_upload` also decodes the incoming base64, writes the file, then reads and base64-encodes the saved file for the response. This makes a folder import with `N` images trend toward repeated full-library work: upload one sprite, re-list/re-encode the growing sprite folder, upload the next sprite, repeat. ## Expected behavior Bulk sprite folder import should import many files with progress, update the query/cache once or in controlled batches, and avoid re-reading/re-encoding the entire sprite library for every file. ## Evidence / code paths - `src/features/catalog/characters/components/CharacterEditor.tsx` - `handleFolderUpload` - `src/features/catalog/personas/components/PersonaEditor.tsx` - `handleFolderUpload` - `src/shared/hooks/use-sprites.ts` - `useUploadSprite` invalidates the sprite list on every upload success - `src/shared/api/image-generation-api.ts` - `spriteApi.list` / `spriteApi.upload` - `src-tauri/src/commands/storage/commands/media.rs` - `sprite_list` / `sprite_upload` commands - `src-tauri/src/commands/storage/sprites.rs` - `list_sprites`, `upload_sprite`, and `sprite_info_from_path` ## Likely bottlenecks - Browser reads each image into base64 before upload. - One Tauri invoke per sprite. - Rust decodes base64, writes bytes, then reads and re-encodes the written file for the response. - React Query invalidates/refetches the complete sprite list after each individual upload. - `sprite_list` returns full base64 data URLs for every sprite, so every refresh scales with total sprite bytes. ## Existing better pattern nearby SillyTavern bulk import already uses a native folder/path-token style flow with Rust-side scanning/copying and progress events: - `src-tauri/src/commands/storage/imports/access.rs` - `src-tauri/src/commands/storage/imports/bulk_imports.rs` - `src/shared/api/import-api.ts` Sprite folder import would likely benefit from a similar native bulk command/event path instead of routing every image through browser base64 IPC. ## Proposed direction 1. Add a bulk sprite import API/command, such as `sprite_upload_bulk` for batched web uploads and/or `sprite_import_folder_events` for native folder imports. 2. For native Tauri, prefer Rust-side folder import after a folder picker selection so the app can copy/read files directly and stream progress. 3. Keep a web fallback that sends an array of upload payloads in one command when native folder access is unavailable. 4. Invalidate `spriteKeys.list(characterId)` once after the bulk import completes, not once per file. 5. Return a bulk result with `{ imported, failed, sprites? }` or progress events, including filenames/errors instead of silently swallowing failures. 6. Consider changing `sprite_list` to return metadata plus managed/local asset URLs instead of base64 image data. This is the bigger contract change but would improve editor load, roleplay overlays, game sprite lookup, tracker portraits, and slash-command sprite listing. ## Verification plan - Import sprite folders with roughly 10, 50, and 100+ images for both characters and personas. - Test both facial-expression and full-body sprite categories. - Confirm existing replacement/name normalization behavior, including `full_` prefix handling. - Confirm failures are reported without aborting the entire import. - Check runtime consumers after import: character editor grid, persona editor grid, roleplay sprite overlay, expression panel/sidebar, game sprite lookup, tracker portrait sprites, and slash-command sprite listing. - Run `pnpm typecheck`, `cargo check --manifest-path src-tauri/Cargo.toml`, and `pnpm check:architecture` for the implementation. ## Notes This issue is based on code-path investigation. It still needs runtime timing measurements before/after implementation to quantify the improvement.
bsakaguchi 2026-10-20 17:30:30 +07:00
Author
Owner

@cha1latte commented on GitHub (May 25, 2026):

Closed in #1201

<!-- gh-comment-id:4536582658 --> @cha1latte commented on GitHub (May 25, 2026): Closed in #1201
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#585
No description provided.