pmmp / BedrockProtocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP
GNU Lesser General Public License v3.0
135 stars 91 forks source link

Performance impact of using closures to handle item decoding #223

Closed dktapps closed 6 months ago

dktapps commented 7 months ago

Profiling the encoding of CraftingDataPacket showed that significant performance losses are made due to the use of multiple closures for every ItemStack encoded.

Two closures are used:

Local experimentation showed ~20% performance improvements from replacing these closures with regular functions. I'm not super clear why closures have such a large performance impact in this case, but we might want to investigate other usages too (e.g. optionals, first-class callables).