Skip to content

Commit

Permalink
fix: CPU overload when loading many nested containers (opentibiabr#2909)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dudantas authored and s2leandro155 committed Sep 26, 2024
1 parent baf2577 commit 0278117
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 0278117

Please sign in to comment.