perf(seller): replace per-pick full auction-house scan with an O(1) duplicate tally - #165
crazy-on-keyboard wants to merge 1 commit into
Conversation
…uplicate tally The seller's DuplicatesCount check re-scanned the entire auction map on every candidate pick. Since Sell() picks up to ItemsPerCycle items per cycle and, when the low-rarity bins are duplicate-saturated, calls getElement() across all 14 rarity/type bins per pick, the cost scaled with roughly O(ItemsPerCycle * bins * auctions) -- i.e. with the square of the auction-house size. On a single-thread-bound server this froze the world loop on large auction houses (Update time diff up to 118s at ~160k auctions, CPU pegged, SOAP/logins unresponsive). Build the per-item tally once per Sell() cycle into an unordered_map and have getElement() do an O(1) lookup instead, keeping it in sync as auctions are posted within the cycle. Behaviour is identical (same DuplicatesCount cap, counted per bot); only the duplicate-check implementation changes. Per-cycle cost drops from ~O(n^2) to O(n).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe auction bot builds one per-cycle tally of its auctions when duplicate limits are enabled. Item selection uses this tally, and successful listings update it. ChangesAuction duplicate tracking
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change replaces an expensive duplicate-count scan with a per-cycle tally while preserving the duplicate cap and has no identified correctness or deployment risk; no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Sell
participant AuctionHouse
participant getElement
Sell->>AuctionHouse: read bot auction counts
Sell->>getElement: pass shared item counts
getElement-->>Sell: return eligible item
Sell->>AuctionHouse: create auction
Sell->>Sell: increment listed item count
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Changes Proposed:
Sell()cycle and looked up in O(1).DuplicatesCountcap, counted per bot); only the duplicate-check implementation changes. No config, schema, or behavioural changes.Why.
AuctionHouseBot::getElement()enforcesDuplicatesCountby re-scanning the wholeAuctionHouseObjectauction map on every candidate pick.Sell()picks up toItemsPerCycleitems per cycle and, when the low-rarity bins are duplicate-saturated, callsgetElement()across all 14 rarity/type bins per pick — so per-cycle cost is roughly O(ItemsPerCycle × bins × auctions), i.e. it scales with the square of the auction-house size. On a single-thread-bound server (Ryzen 1700X) maintaining ~160k auctions this froze the world loop (Update time diff: 118345ms, CPU pegged, SOAP/logins unresponsive). The fix drops per-cycle cost from ~O(n²) to O(n).Issues Addressed:
SOURCE:
for (... GetAuctionsBegin() ...)duplicate scan ingetElement()(src/AuctionHouseBot.cpp), called once per candidate pick fromSell().Tests Performed:
DuplicatesCount = 2, all rarities present, ~39k rare/epic/legendary/artifact listings):DuplicatesCount).How to Test the Changes:
AuctionHouseBot.DuplicatesCount = 2and a highmaxitems).Summary by CodeRabbit