From 88a605cc244a2c3f4c2d3321ea9c0c0b78715d9b Mon Sep 17 00:00:00 2001 From: ishland Date: Fri, 9 Feb 2024 22:49:04 +0800 Subject: [PATCH] perf: limit enhanced autosave iteration to avoid issues with high RD --- .../enhanced_autosave/MixinThreadedAnvilChunkStorage.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/c2me-opts-scheduling/src/main/java/com/ishland/c2me/opts/scheduling/mixin/idle_tasks/autosave/enhanced_autosave/MixinThreadedAnvilChunkStorage.java b/c2me-opts-scheduling/src/main/java/com/ishland/c2me/opts/scheduling/mixin/idle_tasks/autosave/enhanced_autosave/MixinThreadedAnvilChunkStorage.java index 4e7673b33..5dea5ef0f 100644 --- a/c2me-opts-scheduling/src/main/java/com/ishland/c2me/opts/scheduling/mixin/idle_tasks/autosave/enhanced_autosave/MixinThreadedAnvilChunkStorage.java +++ b/c2me-opts-scheduling/src/main/java/com/ishland/c2me/opts/scheduling/mixin/idle_tasks/autosave/enhanced_autosave/MixinThreadedAnvilChunkStorage.java @@ -28,6 +28,9 @@ public abstract class MixinThreadedAnvilChunkStorage implements IThreadedAnvilCh @Shadow @Final private ThreadExecutor mainThreadExecutor; + @Unique + private static final int c2me$maxSearchPerCall = 128; + @Unique private ObjectBidirectionalIterator> c2me$saveChunksIterator; @Unique @@ -51,8 +54,9 @@ private void onTick(CallbackInfo ci) { c2me$enhancedAutoSaveUpdateIterator(); } + int i = 0; final ObjectBidirectionalIterator> iterator = this.c2me$saveChunksIterator; - while (iterator.hasNext()) { + while (iterator.hasNext() && (i ++) < c2me$maxSearchPerCall) { final Long2ObjectMap.Entry entry = iterator.next(); final long pos = entry.getLongKey(); final ChunkHolder chunkHolder = entry.getValue();