⚡ Bolt: Optimize array resizing in bulk load operations#6
⚡ Bolt: Optimize array resizing in bulk load operations#6google-labs-jules[bot] wants to merge 2 commits intomainfrom
Conversation
💡 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.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Refactored `DelayedStart` in `VideoURLProvider.cs` to explicitly call `StartPlaylist()` after loading predefined URLs, correcting a regression where the playlist would initialize but remain idle.
This PR optimizes the$O(N^2)$ array resizing overhead when loading large lists of URLs.
ImageLoaderandVideoURLProviderscripts to eliminateChanges
InitFromGeneratedUrlsto allocate arrays once based on valid count.OnStringLoadSuccessto use a temporary buffer for new items and perform a single resize/copy operation.AddImageIndexmethod.InitFromGeneratedUrlsandOnStringLoadSuccess.AddUrlIndexandRebuildUniquePlaylistmethods.Performance Analysis
AddImageIndexwould be called 100 times, allocating and copying arrays of size 1, 2, ..., 100. Total operations ~5,000.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