Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible performance improvement #532

Open
Punikekk opened this issue Feb 4, 2025 · 0 comments
Open

Possible performance improvement #532

Punikekk opened this issue Feb 4, 2025 · 0 comments

Comments

@Punikekk
Copy link

Punikekk commented Feb 4, 2025

Performance Issue: .getHoverName().getString() Causes Significant Slowdown in Large Storage

public static class ComparatorAmount implements IStoredItemStackComparator {
		public boolean reversed;

		public ComparatorAmount(boolean reversed) {
			this.reversed = reversed;
		}

		@Override
		public int compare(StoredItemStack in1, StoredItemStack in2) {
			int c = in2.getQuantity() > in1.getQuantity() ? 1 : (in1.getQuantity() == in2.getQuantity() ? in1.getStack().getHoverName().getString().compareTo(in2.getStack().getHoverName().getString()) : -1);
			return this.reversed ? -c : c;
		}

		@Override
		public boolean isReversed() {
			return reversed;
		}

		@Override
		public int type() {
			return 0;
		}

		@Override
		public void setReversed(boolean rev) {
			reversed  = rev;
		}
	}
}

The usage of .getHoverName().getString() in the compare method of ComparatorAmount significantly degrades performance when the storage contains a large number of items. Since this method is called frequently during sorting, it introduces unnecessary overhead, especially when dealing with thousands of items.

Same thing goes for other comparators using getHoverName().getString()

Possibly can be replace with id or descriptionIds instead of getting & creating new String each time. I'm new into minecraft modding so I not sure if it possible to replace it with something else, if no them maybe cache them?

Minecraft 1.20.1
Forge 47.3.22

Mod version 1.7.0

I didn't test newer versions

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

No branches or pull requests

1 participant