From bc3e0692621512e7d0a4b024790d00993dab2cd8 Mon Sep 17 00:00:00 2001 From: Blaise Baptist Date: Fri, 14 Aug 2026 16:06:31 -0400 Subject: [PATCH] Avoid redundant HashMap lookup in IngredientMapWrappedAdapter.iterator() iterator() called collection.get(key) for every key already yielded by collection.keySet().iterator(), a wasted second hash lookup for each element. On a large ingredient map with many distinct data-component variants of the same item, that lookup falls into treeified hash buckets and pays for a full equals() chain (DataComparator -> PatchedDataComponentMap.equals -> component-by-component comparison) per element, per collection iteration. In Integrated Terminals, this iterator is on the hot path for rendering/diffing a storage terminal's ingredient view. On a large, diverse network, iterating it while a slot is actively selected (e.g. while dragging an item) can pin the client render thread at 100%+ CPU for tens of seconds, appearing as a full freeze. Iterating entrySet() directly yields the same (key, value) pairs without the redundant lookup. --- .../ingredient/collection/IngredientMapWrappedAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/ingredient/collection/IngredientMapWrappedAdapter.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/ingredient/collection/IngredientMapWrappedAdapter.java index 49e0474364..9a16b4dc58 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/ingredient/collection/IngredientMapWrappedAdapter.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/ingredient/collection/IngredientMapWrappedAdapter.java @@ -80,8 +80,8 @@ public Collection values() { @Override public Iterator> iterator() { - return Iterators.transform(this.collection.keySet().iterator(), - key -> new AbstractMap.SimpleEntry<>(key.getInstance(), this.collection.get(key))); + return Iterators.transform(this.collection.entrySet().iterator(), + entry -> new AbstractMap.SimpleEntry<>(entry.getKey().getInstance(), entry.getValue())); } }