Fix "script ran too long" in ScanExistingItems via lookup tables#962
Open
ptarjan wants to merge 1 commit intoWowRarity:masterfrom
Open
Fix "script ran too long" in ScanExistingItems via lookup tables#962ptarjan wants to merge 1 commit intoWowRarity:masterfrom
ptarjan wants to merge 1 commit intoWowRarity:masterfrom
Conversation
Build spellId/creatureId lookup tables before iterating collections in ScanExistingItems(), converting the inner loops from O(groups * items) per collection entry to O(1) hash lookups. This fixes the "script ran too long" error for players with large collections (~2000+ pets/mounts). Fixes WowRarity#554, WowRarity#753, WowRarity#878, WowRarity#895
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Build
spellId/creatureIdlookup tables before iterating collections inScanExistingItems(), converting the inner loops from O(groups * items) per collection entry to O(1) hash lookups.Fixes #554, #753, #878, #895
Problem
ScanExistingItems()has an O(n*m) nested loop: for each collected mount/pet/companion (~2000+), it iterates through ALL items inR.db.profile.groupsto find matches byspellIdorcreatureId. With 2175 pets and hundreds of tracked items, this produces millions of iterations in a single frame, triggering the "script ran too long" error.Solution
Before iterating collections, pre-build index tables from
R.db.profile.groups:spellIdIndex[spellId]→ list of item entries (for mounts/companions)creatureIdIndex[creatureId]→ list of item entries (for pets)The mount, companion, and pet inner loops are replaced with O(1) hash lookups via
ipairsover the matching entries.Complexity improvement:
Test plan
/reloadwith 2000+ collected pets — no more "script ran too long"