From 0278117bbcf9a658859288c8325db1c9d0b4095c Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 24 Sep 2024 18:03:05 -0300 Subject: [PATCH] fix: CPU overload when loading many nested containers (#2909) This addresses an issue where excessive CPU load occurs when dealing with deeply nested containers due to repeated calls to the `isRemoved` function in the `canDecay` method. To mitigate this, the order of checks in `canDecay` has been changed to evaluate the decay conditions first, and only check for removal status (`isRemoved`) as the last step. --- src/items/item.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/items/item.cpp b/src/items/item.cpp index dd2d5c965a6..2ad0cfa4abd 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -3160,16 +3160,17 @@ void Item::addUniqueId(uint16_t uniqueId) { } bool Item::canDecay() { - if (isRemoved() || isDecayDisabled()) { + const ItemType &it = Item::items[id]; + if (it.decayTo < 0 || it.decayTime == 0 || isDecayDisabled()) { return false; } - const ItemType &it = Item::items[id]; - if (it.decayTo < 0 || it.decayTime == 0) { + if (hasAttribute(ItemAttribute_t::UNIQUEID)) { return false; } - if (hasAttribute(ItemAttribute_t::UNIQUEID)) { + // In certain conditions, such as depth nested containers, this can overload the CPU, so it is left last. + if (isRemoved()) { return false; }