Placing/breaking blocks or running redstone in a chunk with block entities containing items (such chests containing items/shulkers) can cause significant server performance issues.
Steps to reproduce:
1. Download & load up the "Performance Test World" attached to this bug report.
2. Press Alt+F3 to bring up the debug screen with performance graphs.
3. Turn on the redstone clock that's inside the same chunk as the chests containing shulkers full of items.
4. Observe the poor performance in the TPS graph.
Upon running the built-in debug performance profiler, the majority of the server tick time is seen being consumed by "chunk_unload". It appears that whenever a chunk experiences a change, the game will attempt to save that chunk regardless if the chunk had already been saved recently or not. Disabling auto-save in a multiplayer server with the /save-off command will see performance return to normal, confirming the cause of this issue is the current implementation of auto-save.
When testing previous versions of the game I've found 1.18-pre6 to be the first version to exhibit this issue. Versions 1.18-pre5 and earlier are unaffected by this specific scenario.
In 1.18-pre6 a technical change to auto-saving was made:
"The game now saves chunks whenever there is time spare to reduce autosave spikes" https://feedback.minecraft.net/hc/en-us/articles/4414372344205-Minecraft-Java-Edition-1-18-Pre-Release-6
This technical change may have been made in an attempt to address another issue: MC-239474
MC-243760 may also be related.
Additionally I’ve also observed increased memory usage during testing. I speculate that a lot of short lived objects may be getting created every time chunk data is saved, causing higher memory usage and more frequent GC’s. However I’m not able to do code analysis so I cannot confirm if the increased memory usage I’ve seen is related to this issue.
I first discovered this issue when I updated a singleplayer creative world that had a small storage system in it to 1.18.1. I noticed that when I ran that storage system performance was significantly worse then it was 1.17.1. Instead of only consuming 3-5 MSPT like it did in 1.17.1, it was now running at almost 50 MSPT.
Turns out this issue is similar to MC-245910 which was just fixed in 22w05a.
This issue is now (mostly) no longer present as of 22w05a.
Running the performance test again in 22w05a will still see the spikes in the TPS graph, however a spike will only appear every 10 seconds instead of the continuous spikes as seen in versions 1.18-pre6 to 22w03a. It appears that in 22w05a when a chunk experiences changes it will only be auto-saved as frequently as every 10 seconds now. Scenarios such as running a small storage system sees performance return to around where it was in 1.18-pre5.