your current location:首页 > news>Minecraft Thread Pool Agent Minecraft

Minecraft Thread Pool Agent Minecraft

2024-12-12 09:33:05|Myriagame |source:minecraft skins

use

Note: This is Java Agent!

This is not used in the Mods folder. It needs to be placed in the main directory (Config, Lib, SAVES, and SAVES), and edit the startup command.

How to use:

Download jar, add the following sentences to the start code:

-DMINECRAFTTHREADPoolSize = 2 -DMineCraftbootstradPoolSize = 1 -DMineCraftMainThreadPoolsize = 2-JavaAgent: Minecraft-Thread-popit-1 .0.0-shded.jar

introduce

This is a Java Agent program that can improve Minecraft startup speed and solve the problem of 100% of the CPU accounting for a period of time after loading.

Both the server and the client are effective.The original, Spigot (Paperspigot already has a related options that can use Paper.workrthreadCount), Forge, Fabric.

The author has only tested on 1.14 and 1.16, and the rest of the version needs to be tested.Active E8600+8G memory open 1.16 client can feel a significant improvement

The version below 1.13 is not applicable, and there is no such problem at that time.

Configuration

The configuration option:

TheSe are syster property passed as -dopting = value jvm arguments.

Default Vanilla Pool Size is Clamp (Processor_Count -1, 1, 7). Processor_count refers to the number of threads, including physical core and hyper -thread.

MinecrafthreadPoolsize (Any Version): Changes Size of All Pools. Parameters Below Will Overwrite This Value.

MinecraftmainthReadpoolsize (1.16+): CHANGES Main Thread Pool Size (Used for Loading Resources).

MinecraftBootstrapthreadPoolsize (1.16+): Changed Bootstrap Thread Pool Size (Used for Rewriting and Optimizing DataFixer Types).

principle

Working principle:

Information below is for 1.16 and was expected that analyzing defiled client code.

At the start, Client or Server Creates Two Thread Pools: Main and Bootstrap. There are Other Pools, but they are not importing work.

Main Thread Pool is used to recoad resource managers. During Reload, A Resource Manager Scans Associations and ResourcePacks, Loads Models Ans Textus, Creates Tex TURES Atlase and Does Many Other Related Things.

Bootstrap Thread Pool is used to rewrite datafixer types. Minecraft Declares a set of schemas, each schema containing types. ntergrated into mincraft, since their datafixers library is overcomplicated and users abstractions that are impossible to undertand with mathematical.Background.anyway, there is a type rewrite stage, in which each declired type is rewritten obtimization. Formance Optimization.a Lot of Garbage Objects and consumes a Lot of CPU (The Code Must be compired by jvm and this garbage must be together).

Most Importand Thing in the Pools Are their Sizes. By Default, These Pools Have Size that is called, Essor_count is the result of calling runway.getruntime (). AvailableProcessors (). ThisMethod Returns Not Physical Processor Count and Not Physical Core Count, But "Logical" Processor Count, Meaning If You Have 4 Cores with Hyperthreading, IT Will Return 8. Also, OS Can Limit Code Count that is available for process, and Result of thisMethod will reflect it, but this is not importing work.

For exmple, on 4 Cores/8 Threads Machine the Pools Wills Will Have Size CLAMP (8-1, 1, 7) = 7, Meaning there is 14 Threads Total for the Two Executors.

Performance factors:

This is very bad for performance: Type rewriting and gc are cpu-breaks, meaning while they working, they will fully consume a CPU core. s do not consume that much CPU becape they are free.Resource (File, Socket, ETC.) and CPU Can Do Other Tasks While IO-BOUND TASK IS WAITING.IF You Have More CPU-BOND TAN PHYSICAL CORLS, Tasks Will Comp that ETE and Work Slower. Even your PC May Start Lagging, BeCAUSEThere is less CPU Time for OS-Related Tasks and Other Applications.

The Answer to the Question "Why SINCE 1.14 Minecraft Consumes Too Much CPU on Start?", Therebeore, is: MineCraft Creates to Many Threads to Rewrite DataFixer Types and Load Resources and Does Not Consider Physical Core Count, ITS OTHER Executors and the Time Neededfor gc to do its work.

The solution is to Reduce Thread Pool Sizes to Adequate Numbers, 1-3 Threads for Each Executor. Ojang Decided Not to Wait for Rewriting Completing at Startup and Alowing Player to loadWorld or Connect to a Server Immediaately After Resources Are Loaded, this might not being.

SPECIFICALLY, 1 Thread for Bootstrap Executor and 2 for Main Work ESPECIALY WELL on My Setup. Resource Loading Theoretical May Benefit FROM MOREADS, But Y ou can test it your safety.

After pointings we reduced, startup time significantly increase and CPU load is heaviliy reduced.

Agent and bytecode:

To make my solution as universal as postible, I use a java installment framework and ASM Library to Manipulating of loaded classces at rantime. Allows me to Not Bother with Creating and Distributing Patches (MODS).

There is network.mineCraft.util class containing fireds string Executors (thread pools). Executors are created user method that is Called When class is B Eing Initialized.i Add Call to Agentruntime.replacePool Method BeFore These Private Methods Return a Value,Allowing me to reply thedese pools if needed. in this method I do trivial thing like checking system property and creating new instance of forkjoinPool.

To detect util class, I used some heuristics like "a class must contain at Least x fields ans ythods, all fields and methads must be static, there are be must be must S Logger and Executorservice Fields ". This allows me to not depend on Concrete namesand obfuscation maps.

To Measure Start Time I Apply Another Patch to Net.minecraft.mineCraft Class. Ke Server Does).

Idd a call to agingruntime.startProfiling into the constructor and a call to agentruntime.ndprofiling to any Private Synthetic Ional jump opcode. There is a callback lambda that is called when resource manager Finishes reloading, and that is theActual moment when minecraft client becomes responsive. So, placing endprofiling call her seem reasonable.

Endprofiling Prints Measud Time Into Stdout:

[Stdout]: Done Initial Relaad of Resource Manager, 11.60 Secnce Passed Since Start.