-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
148 changed files
with
826 additions
and
2,687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
c2me-base/src/main/java/com/ishland/c2me/base/ModuleEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.ishland.c2me.base; | ||
|
||
import com.ishland.c2me.base.common.config.ConfigSystem; | ||
import io.netty.util.internal.PlatformDependent; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
public class ModuleEntryPoint { | ||
|
||
private static final boolean enabled = true; | ||
|
||
public static final long globalExecutorParallelism = new ConfigSystem.ConfigAccessor() | ||
.key("globalExecutorParallelism") | ||
.comment("Configures the parallelism of global executor") | ||
.getLong(getDefaultGlobalExecutorParallelism(), getDefaultGlobalExecutorParallelism(), ConfigSystem.LongChecks.THREAD_COUNT); | ||
|
||
private static int getDefaultGlobalExecutorParallelism() { | ||
return Math.max(1, Math.min(getDefaultParallelismCPU(), getDefaultParallelismHeap())); | ||
} | ||
|
||
private static int getDefaultParallelismCPU() { | ||
if (PlatformDependent.isWindows()) { | ||
return Math.max(1, (int) (Runtime.getRuntime().availableProcessors() / 1.6 - 2)) + defaultParallelismEnvTypeOffset(); | ||
} else { | ||
return Math.max(1, (int) (Runtime.getRuntime().availableProcessors() / 1.2 - 2)) + defaultParallelismEnvTypeOffset(); | ||
} | ||
} | ||
|
||
private static int defaultParallelismEnvTypeOffset() { | ||
return isClientSide() ? -2 : 0; | ||
} | ||
|
||
private static boolean isClientSide() { | ||
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; | ||
} | ||
|
||
private static int getDefaultParallelismHeap() { | ||
if (PlatformDependent.isJ9Jvm()) { | ||
return (int) ((memoryInGiB() + (isClientSide() ? -0.6 : -0.2)) / 0.5) + defaultParallelismEnvTypeOffset(); | ||
} else { | ||
return (int) ((memoryInGiB() + (isClientSide() ? -1.8 : -0.6)) / 1.4) + defaultParallelismEnvTypeOffset(); | ||
} | ||
} | ||
|
||
private static double memoryInGiB() { | ||
return Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.