Skip to content

Fix "script ran too long" in ScanExistingItems via lookup tables#962

Open
ptarjan wants to merge 1 commit intoWowRarity:masterfrom
ptarjan:fix-scan-existing-items-performance
Open

Fix "script ran too long" in ScanExistingItems via lookup tables#962
ptarjan wants to merge 1 commit intoWowRarity:masterfrom
ptarjan:fix-scan-existing-items-performance

Conversation

@ptarjan
Copy link
Copy Markdown

@ptarjan ptarjan commented Feb 22, 2026

Summary

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.

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 in R.db.profile.groups to find matches by spellId or creatureId. 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 ipairs over the matching entries.

Complexity improvement:

  • Before: O(collections × groups × items) per scan
  • After: O(groups × items) to build index once + O(collections) to scan

Test plan

  • /reload with 2000+ collected pets — no more "script ran too long"
  • Rarity correctly marks owned mounts/pets as found
  • Tooltip still shows collection status for tracked items

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
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.

1x Rarity/Core/Collections.lua:196: script ran too long

1 participant