pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.28k stars 1.56k forks source link

Performance issue in BlockStateUpgrader #6277

Closed dktapps closed 8 months ago

dktapps commented 8 months ago

Description

This loop usually doesn't apply any changes to worlds from the latest version: https://github.com/pmmp/PocketMine-MP/blob/b0390a39fd1eb2d5b524f834fd0866057574d34f/src/data/bedrock/block/upgrade/BlockStateUpgrader.php#L64

However, we're still iterating all the schemas anyway. Turns out this is actually quite a big performance issue, contributing on average about 20% of the total load time of chunk data (tested with a 1.20.60 vanilla world).

It's a pain to address, since we can't start the foreach at the position where the schemas would actually apply. We'd need a binary tree, or perhaps a cache for lists of schemas applicable to particular versions to avoid this.

Related to #6149

Alternative methods

dktapps commented 8 months ago

I attempted to use LimitIterator to fix this, but apparently the seek still involves a while loop. What a stupid design ...

dktapps commented 8 months ago

Fixed by 8ec304e66e489b1dd4d4c2f7b6493e70212a01e3 and a6202d0442029ffe628484cb9ac1135e400229d4.