Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

NBTTagCompound.equals() perfomance suggestion #599

Open
gamerforEA opened this issue Dec 14, 2016 · 2 comments
Open

NBTTagCompound.equals() perfomance suggestion #599

gamerforEA opened this issue Dec 14, 2016 · 2 comments

Comments

@gamerforEA
Copy link
Contributor

gamerforEA commented Dec 14, 2016

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.
}
@spannerman79
Copy link
Contributor

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

@gamerforEA
Copy link
Contributor Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants