[SPIGOT-2503] Block type change produces unnecesary light updates Created: 07/Jul/16 Updated: 09/Jul/16 Resolved: 08/Jul/16 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | Pablete1234 | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | Craftbukkit |
Description |
Block#setTypeIdAndData first replaces the block to air, and then to the block you are trying to set it to. This is a performance issue, specially notable when you have light sources, completly encased in any material, and you replace all the outside material, it creates massive lag spikes as every single block creates light updates when replaced with air, and again when it gets placed back to another solid block. This was a workarround added as a fix for SPIGOT-611, but it's done with any type of block, air should only be set if the block you are replacing is a tile entity. Code causing the truble here |
Comments |
Comment by md_5 [ 09/Jul/16 ] |
No, its magnitudes cheaper than getTypeId. Thats why it was placed this way. |
Comment by lizardfreak321 [ 09/Jul/16 ] |
Can we have instanceof after the: type != getTypeId() instanceof is significantly more expensive than primitive equality checks. In my rollback plugin, adding a single instanceof to the loop increased the time spent on the operation from 0.6 seconds to 1.3 second which is a huge jump! And my plugin also uses setTypeIdAndData.. but I check to make sure the ID is different anyways. Also if you can somehow find a different solution than instanceof that will really help. |
Comment by Pablete1234 [ 08/Jul/16 ] |
"but it's done with any type of block, air should only be set if the block you are replacing is a tile entity." One of the simplest solutions would be to only set it to air if it's a tile entity, that would already reduce the odds of it happening by alot. The other (proper) way of solving this, would be to properly delete the tile entity (if there is one) instead of setting air to get rid of it |
Comment by md_5 [ 08/Jul/16 ] |
Right, and do you have a solution? |