AI Update bulk-animations.js big perf pass — cache geometry, avoid in… #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background: i was facing major perfomance issue on very large tileset (Tiled UI get frozzen for more than 5 min and prone to crash). I decided to let an AI rewrite a performance patch and there is a massive performance improvement on all of my large tileset (instant vs 5 mins).
Only tested in windows version of Tiled but i think it should work on every supported platform
Since this is patch is writen by AI someone need to try if every fonctionnality was preserved and no bug was induced, so far i only tested created and removing some animations in diffents configuration but maybe not all possible settings
At least on my side it provide a massive improvement (from unsuable to ultra fast) so i think it should be worth checking or making available in a separate download on release so people can use it when performance maters
BulkAnimationEditor: major performance pass (cache sizes, avoid
indexOf, macro batching)Summary
This PR removes several O(n²) hot paths and batches edits to avoid UI stalls when creating animations for large selections. Dialogs now open promptly and animation creation scales much better on big tilesets.
Motivation
When selecting many tiles and choosing Create Bulk Animations From Selection, Tiled would appear frozen for minutes before the configuration dialog appeared. The main causes were repeated linear searches over
tileset.tilesand repeated recomputation of geometry derived from the tileset.Key Changes
Replace
indexOflookups with ID mathgetTileCoord,getSelectionExtent, and rectangle checks now compute(x, y)directly fromtile.idusing cachednumCols.Introduce a lightweight cache
numCols,numRows, the sortedselectedTiles, and the computedextentfor reuse across validations and UI updates.Batch mutations with
tileset.macro(...)Remove full-tileset scans inside loops
tileset.tiles.filter(t => t === null)per tile. We now validate per-frame tiles as we build frames.Robust frame building
getFramesadvances by computedidStrideand retrieves tiles viatileset.findTile(id)(fallback totileset.tile(id)), aborting gracefully if a referenced tile is missing (important for image‑collection tilesets with sparse IDs).Safer, faster rectangle checks
isSelectionRectangularuses the cached selection and expected contiguous ID pattern without extra searches.UI correctness preserved
framesInput.maximumupdates when direction/stride changes.Performance Impact
indexOfcalls → transforms several workflows from O(n²) to O(n) over the selection.Compatibility
tileset.findTile(id)when available (Tiled ≥ 1.9.2), otherwise falls back totileset.tile(id).Risk & Edge Cases
findTile/tilechecks.Testing
Open a large tileset (thousands of tiles).
Select a large rectangular region; run Create Bulk Animations From Selection.
Try directions Right, Down, Both with various strides and frames (including 0 = until end).
Repeat on an image‑collection tileset to confirm graceful handling of missing IDs.
Use Clear Animations In Selection and verify a single undo step restores all frames.
Future Work
isSelectionRectangular()on very large, irregular selections.Notes
Version bumped to
1.3.2-p1to indicate a performance patch.