CyberdyneCC / Thermos

(NO LONGER DEVELOPED) Minecraft Forge Server Software implementing the Spigot/Bukkit API, formerly known as Cauldron/MCPC

Home Page:http://cyberdynecc.github.io/Thermos/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NBTTagCompound.equals() perfomance suggestion

gamerforEA opened this issue · comments

Mods Installed:
ThermalDynamics

Warmroast Report: (Optional)
http://paste.enginehub.org/CuVc9L.profile

Thermos Version:
58-ALPHA

Forge Version:
1614

Explanation of issue:
In WarmRoast report ~36% CPU load is NBTTagCompound.equals() method. This method compares HashMap, but it's very slow. I suggest compare hashCode at first to escape checking the obviously different NBTs. That hashCode() be fast, we may cache he value and update it on change NBT. For example:

private int hash;

public void setInteger(String key, int value) {
   // Set value
  this.markDirty();
}

private void markDirty() {
   this.hash = 0;
}

public int hashCode() {
   if (this.hash == 0) this.hash = oldHashCode(); // Old hashCode() function
   return this.hash;
}

public boolean equals(NBTTagCompound other) {
   return this.hashCode() == other.hashCode() && oldEquals(other); // Compare hash and old equals() function.
}

@gamerforEA I suggest that you submit a PR with your changes.

Hmmm... Problem.
The NBTTagCompound returns a NBT (for example other NBTTagCompound), on the changes that the parent NBT is not aware. Make references to parents in child NBTs - not the best idea. I don't know how to solve this problem.