Skip to content

⚡ Bolt: Optimize array resizing in bulk load operations#6

Open
google-labs-jules[bot] wants to merge 2 commits intomainfrom
bolt/optimize-array-resizing-7048175253732789028
Open

⚡ Bolt: Optimize array resizing in bulk load operations#6
google-labs-jules[bot] wants to merge 2 commits intomainfrom
bolt/optimize-array-resizing-7048175253732789028

Conversation

@google-labs-jules
Copy link
Contributor

This PR optimizes the ImageLoader and VideoURLProvider scripts to eliminate $O(N^2)$ array resizing overhead when loading large lists of URLs.

Changes

  • Scripts/ImageLoader.cs:
    • Refactored InitFromGeneratedUrls to allocate arrays once based on valid count.
    • Refactored OnStringLoadSuccess to use a temporary buffer for new items and perform a single resize/copy operation.
    • Removed unused AddImageIndex method.
  • Scripts/VideoURLProvider.cs:
    • Similar refactoring for InitFromGeneratedUrls and OnStringLoadSuccess.
    • Removed unused AddUrlIndex and RebuildUniquePlaylist methods.

Performance Analysis

  • Old Behavior: For a list of 100 images, AddImageIndex would be called 100 times, allocating and copying arrays of size 1, 2, ..., 100. Total operations ~5,000.
  • New Behavior: Counts valid items (1 pass) or fills temp buffer (1 pass), then allocates final array (1 allocation) and copies old + new data once. Total operations ~200 (proportional to $N$).

This is particularly important in UdonSharp where array operations can be relatively expensive compared to native C#.


PR created automatically by Jules for task 7048175253732789028 started by @AEmotionStudio

💡 What:
Replaced iterative array resizing (resizing +1 for each item) with a batch allocation strategy in `ImageLoader.cs` and `VideoURLProvider.cs`.

🎯 Why:
The previous implementation used "Shlemiel the Painter's algorithm" ($O(N^2)$) when loading URL lists, causing significant performance overhead and memory garbage generation during initialization or network refreshes with large lists.

📊 Impact:
- Reduces array allocations from $N$ to 1 per load operation.
- Reduces time complexity of adding $N$ items from $O(N^2)$ to $O(N)$.
- Significantly reduces GC pressure during playlist/slideshow updates.

 microscopes Measurement:
Verify by loading a large list of URLs (e.g., 100+ items). The operation should complete instantly without frame drops, compared to a noticeable stutter in the previous version.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@AEmotionStudio AEmotionStudio marked this pull request as ready for review January 15, 2026 01:22
Refactored `DelayedStart` in `VideoURLProvider.cs` to explicitly call `StartPlaylist()` after loading predefined URLs, correcting a regression where the playlist would initialize but remain idle.
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.

1 participant