Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3596

CraftBlock.getRelative() could have performance significantly improved

XMLWordPrintable

    • TrainCarts

      After performing a server performance checkup using VisualVM Im noticing a very apparent performance drain on the server: Block.getRelative(). This is used a lot to 'walk' down blocks, or to simply get the block above or below. The problem is, that a call to getRelative redirects to a call to World.getBlockAt. This has the nasty side-effect that it looks up the chunk of the block again every single time its called.

      This is a waste of cpu, because 100% of the time it will be the same chunk when y is 0, and in other cases when using getRelative with block faces it will be the same chunk 15/16 times. I would love it to be fixed, so I don't have to roll a hackish workaround myself.

      The included logs are under a very simple test with only a few entities with the TrainCarts that are being updated. That function is being called a lot of times in more serious environments, trust me. It is presently 70% of the cpu usage TrainCarts is using, which I think is too much considering all the things TC updates every tick. getRelative really shouldn't be this slow.

      Reason it is used a lot: walking down tracks (iterative).

      I would love to see it fixed, at least for getRelative(BlockFace) because of the almost-guarantee the relative position is going to be sub-chunk.

            Unassigned Unassigned
            bergerkiller Irmo van den Berge
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: