SolvedPaper Disable precreation of all possible BlockStates

Basically, since 1.8 there is a terrible start time regression when these dumbb BlockStates were introduced.
Minecraft precreates a BlockState for each combination of metadata values.
The idea was good, it's nice that they are deduplicated in memory.
The problem is that some blocks have a LOT of possible BlockStates.
For example, Fire has around 4096 possible combinations etc. I don't remember which ones exactly.

It takes more than a second to do all this and the server is stuck at Loading libraries...
I made a patch for 1.8, deployed and forgot about this, it's extremely tricky and volatile, makes the BlockStates lazy-create when a new one is needed, this drops the load time from more than a second to 70ms.

(very easy to break this patch in many ways and then you see weird behaviour like: can't place redstone but you can place other blocks, when you break a double flower the upper part stays etc. I've made a few testcases to ensure the patch is working)

I've never ever seen it crash on my minigames, but it can crash with some BlockState not found error when creating a new world and going to a jungle or something so I don't know what's wrong.

Have anyone tried speeding this up before?
Is anyone interested in helping fixing up the patch and bringing it to 1.12?
I'll upload a proof of concept in that case.

21 Answers

✔️Accepted Answer

I'm 100% against this. It's unnecessary to make micro optimizations to server start time and risk introducing bugs.

>>> date ; java -DIReallyKnowWhatIAmDoingISwear=1 -XX:+UseG1GC -jar ../../Paper-Server/target/paper-1.12.jar
Mon Jul 10 14:51:55 EDT 2017
Loading libraries, please wait...
[14:51:58 INFO]: Starting minecraft server version 1.12
[14:51:58 INFO]: Loading properties
[14:51:58 INFO]: Default game type: SURVIVAL
[14:51:58 INFO]: This server is running Paper version git-Paper-"0efa08cb" (MC: 1.12) (Implementing API version 1.12-R0.1-SNAPSHOT)
[14:51:58 INFO]: Debug logging is disabled
[14:51:58 INFO]: Server Ping Player Sample Count: 12
[14:51:58 INFO]: Using 4 threads for Netty based IO
[14:51:58 INFO]: Enabled sleeping between chunk saves, beware of memory issues
[14:51:58 INFO]: Generating keypair
[14:51:58 INFO]: Starting Minecraft server on
[14:51:58 INFO]: Using epoll channel type
[14:51:59 INFO]: Set PluginClassLoader as parallel capable

3 seconds of startup is fine. Plugins and Worlds are going to be 3-10x that.

More Issues: