Skip to content

Conversation

@aikar
Copy link
Member

@aikar aikar commented Jan 18, 2018

Optimize Hoppers

  • Lots of itemstack cloning removed. Only clone if the item is actually moved
  • Return true when a plugin cancels inventory move item event instead of false, as false causes pulls to cycle through all items.
    However, pushes do not exhibit the same behavior, so this is not something plugins could of been relying on.
  • Add option (Default on) to cooldown hoppers when they fail to move an item due to full inventory
  • Skip subsequent InventoryMoveItemEvents if a plugin does not use the item after first event fire for an iteration

Closes #392

+ } else if (ihopper instanceof EntityMinecartHopper) {
+ ((EntityMinecartHopper) ihopper).setCooldown(ihopper.getWorld().spigotConfig.hopperTransfer / 2);
+ }
+ return false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self, change this to true. false causes this code to be ran for every item. but because we are mode 2, we know item is not going to change the fact this event was cancelled.

return true in mode 0 too. i was originally concerned it would block plugins who want to cancel first and allow 2nd, but the same cant be said for push mode, so we can just make them consistent, and greatly improve performance of cancelled pulls.

@UberMC
Copy link

UberMC commented Jan 19, 2018

This looks interesting!

@aikar aikar changed the title Optimize Hoppers with Plugin Heuristics Optimize Hoppers Jan 20, 2018
@aikar
Copy link
Member Author

aikar commented Jan 20, 2018

Exciting, found ways to do these optimizations always without any mode setting, greatly reducing diff and should keep things super safe with plugins.

@aikar
Copy link
Member Author

aikar commented Jan 20, 2018

I have uploaded a paperclip patcher for this patch to <outdated, see Z's link below>

I would love to get feedback from users with bad hopper timings who use protection plugins or other hopper related plugins.

I'm more interested in knowing that behavior isn't broken than I am about performance, but if you can get a before and after timings/profiler results, that would be good too.

@RoboMWM
Copy link

RoboMWM commented Jan 20, 2018

I personally would like a mode 0 or 1 toggle at the very least so I can just ignore/effectively eliminate the event regardless if plugins use it but I guess the best way to go about that is to do something similar to eliminating use of PlayerChatEvent.

@aikar
Copy link
Member Author

aikar commented Jan 20, 2018

@RoboMWM There was a config added for that.
https://github.com/PaperMC/Paper/pull/976/files#diff-2818bedee6c292733614b57195f52435R25

@aikar
Copy link
Member Author

aikar commented Jan 25, 2018

Updated patch to be on top of the latest Paper as of today (with my Cat Hopper Performance fix too)

Updated configs to be under the existing hopper. section

fixed bug with suck in code not returning false for item not found, and also fixed it to respect the cooldown if full setting.

This should be good to go now, need testers.

@NullCase
Copy link

Re: hoppers picking up dropped items...

Items still enter blocked hoppers given hoppers: Push-based true

@mibby
Copy link

mibby commented Feb 5, 2018

@aikar Is there any easy way to apply your patch on top of the latest paper jar? I tried compiling upstream with your PR merged but am running into issues with the decompile script during compilation.

I ran a timings profile recently and noticed the majority of my tick impact was coming from InventoryMoveItemEvent by two plugins (WorldGuard / ChestShop). I could probably be used as a helpful test candidate to see how much improvement is made with your optimization patch.
https://timings.aikar.co/?id=c6ccbd224d894c3690de6e78aac5d082#timings

@zachbr
Copy link
Contributor

zachbr commented Feb 5, 2018

This patch applied to latest (1322)
https://zachbr.keybase.pub/paper/github/pulls/976/paperclip.jar

@mibby
Copy link

mibby commented Feb 6, 2018

So far early timing indication shows a massive improvement to hopper performance in my environment. I do not notice InventoryMoveItemEvent in the timings profile whatsoever. I will report back later today with a new timings report during around peak hour at the same time as the earlier report.

    hopper:
      cooldown-when-full: true
      disable-move-event: false
      push-based: false

@aikar
Copy link
Member Author

aikar commented Feb 6, 2018

@mibby behavior wise, does things still function as expected? IE WorldGuard / chestshop able to block restricted hopper access, etc?

If so, then we will be good to merge this!

@aikar aikar changed the title Optimize Hoppers Optimize Hoppers - Closes #392 Feb 6, 2018
@mibby
Copy link

mibby commented Feb 7, 2018

@aikar I believe so. I created a ChestShop shop for testing and couldn't move items out via a hopper. Protecting a chest via LWC, couldn't move items out via hopper unless flagged to do so. Hoppers can move items out of normal chests like vanilla behavior just fine.

Unsure how to test hoppers with WorldGuard since there is no protection flag for it. I assume it is also working fine as intended since the above does.

New timings with no noticeable impact from InventoryMoveItemEvent. However I doubt the same problem chunks that initially caused the load are presently loaded in this timings, but at first glance, greatly improved performance.
https://timings.aikar.co/?id=7620516f970a456c9b48c27f9bb7fae5#timings

@ArtNRG
Copy link

ArtNRG commented Feb 9, 2018

Items can't get into the hopper through a soil with this optimization.

  • push-based: true
  • cooldown-when-full: true
  • disable-move-event: true

@aikar
Copy link
Member Author

aikar commented Feb 9, 2018

@ArtNRG what do you mean through a soil? This change doesn't alter hopper suck in mechanics, it impacts the Bukkit Event.

Try with push-based disabled, as that is not related to this PR.

- Lots of itemstack cloning removed. Only clone if the item is actually moved
- Return true when a plugin cancels inventory move item event instead of false, as false causes pulls to cycle through all items.
  However, pushes do not exhibit the same behavior, so this is not something plugins could of been relying on.
- Add option (Default on) to cooldown hoppers when they fail to move an item due to full inventory
- Skip subsequent InventoryMoveItemEvents if a plugin does not use the item after first event fire for an iteration
@aikar aikar merged commit 094bb03 into master Feb 13, 2018
@aikar aikar deleted the optimize-hoppers branch March 7, 2018 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants