Skip to content

Conversation

@CodeWithBehnam
Copy link
Owner

Summary

Fixes performance issues when viewing large (4K) generated images that caused:

  • Slow image loading in the modal
  • Browser becoming unresponsive
  • Page reloading due to memory pressure

Root Cause

Large images stored as base64 strings (10-20MB+) were being passed directly to <img> tags as data URLs. This caused:

  1. Massive memory allocation when parsing the base64
  2. Browser struggles to decode and render full-resolution images
  3. Page crashes when memory limits are exceeded

Solution

Convert base64 strings to Blob URLs which are much more memory-efficient:

  • Blob URLs are references to binary data in memory, not the data itself
  • Browser handles blob data more efficiently than inline base64
  • Added caching to avoid repeated conversions

Changes

  • New src/lib/image-utils.ts: Utility functions for base64 to blob URL conversion with LRU caching
  • Updated ImageModal.tsx: Uses cached blob URLs instead of data URLs
  • Updated BaseNode.ts: Uses blob URLs for image preview loading

Test plan

  • Generate a 4K image
  • Click on the image to open the modal - should open quickly
  • Page should remain responsive
  • No browser crashes or reloads

Behnam Ebrahimi

- Add image-utils.ts with base64 to blob URL conversion
- Update ImageModal to use blob URLs instead of data URLs
- Update BaseNode loadImage to use cached blob URLs
- Add LRU cache for blob URLs with automatic cleanup

This significantly improves performance when viewing 4K images by:
- Converting base64 strings to blob URLs which are more memory-efficient
- Caching blob URLs to avoid repeated conversions
- Reducing browser memory pressure that caused page reloads

Co-Authored-By: Behnam & Claude Code
@CodeWithBehnam CodeWithBehnam merged commit a1ba4c7 into main Dec 25, 2025
2 checks passed
@CodeWithBehnam CodeWithBehnam deleted the fix/large-image-performance branch December 25, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants