Lag when using Loot Audit plugin

The title isn't clickbait for me and I know the cause (I think). 

I use Vehicle Storage and a logging tool called Loot Audit. When you sort a vehicle storage, the way this works is the sort button removes every item from the storage (I know this because loot audit thinks you've looted it) then replaces it.

There have been 2 players that have figured this out and decided to spam the sort button absolutely destroying the server and its framerate causing issues for other players.

I know the image show that it's "loot audit" causing this, but it's only when you press sort and it's only when sorting a vehicle storage container. I don't know if it's possible, but I think the solution be that when sorting a vehicle storage it doesn't remove everything then replace everything. 

https://imgur.com/bVqczU3

https://imgur.com/DddIOFk

This can be optimized, but I'm not sure it truly needs to be. In vanilla, removing and adding all items from the container is a relatively inexpensive operation which I have benchmarked (takes microseconds to sort a container). The issue occurs when other plugins globally hook them move events, and have expensive implementations of those hooks. That second screenshot shows LootAudit taking lots of time for the OnDispenserGather hook which isn't even used by SortButton. That plugin appears to be poorly optimized according to your logs.

NKXTQs24ExGTuL8.jpg WhiteThunder

Have you confirmed that the lag comes from clicking the sort button as opposed to the C/N button? In the past, lag has been reported with the C/N button if the data file is large, and I plan to change the saving logic to only save that data once in a while, as well as remove any preference matching the server default to keep the file smaller, but haven't prioritized that yet. If you are experiencing this issue, you can partially mitigate it by clearing the data file.

I find it unlikely that removing all the items and adding them back would cause lag because that is a relatively inexpensive operation which I have benchmarked multiple times. However, if many plugins are hooking item move events, and/or those plugins have expensive implementations of those hooks, then that could compound the cost of the operation, but I would suggest also looking at optimizing those plugins.

I've confirmed this myself, and I've had confirmation from the 2 that abused this and confirmation from 2 other players that tried this for me that it is for certain the sort button itself, but only within vehicle storage.

Loot Audit is fine with everything else, it's really just when sorting vehicle storage that issues arise. 

Ok I'll make an update soon, to move the items in place.

NKXTQs24ExGTuL8.jpg WhiteThunder

Ok I'll make an update soon, to move the items in place.

I'll see if I can make adjustments to loot audit too. The plugin developer for that is aware of issues too and said back in May that he's almost done with a rework of that plugin too. Given how close that is to being finished, he's not going to update this until that's released. 

I'll let you know if I'm able to change the config to lessen this issue.

I looked into this and now remember why the plugin doesn't sort in place. One feature players come to rely on from this plugin is that sorting automatically consolidates multiple item stacks if possible. If the plugin were to sort in place, that consolidation logic would need to be reimplemented by the plugin. To give an idea, the vanilla function for moving an item to a container is about 180 lines of decompiled code, and a lot of that is focused on stack consolidation. It wouldn't be a good idea for the long term maintainability of the plugin to duplicate that logic because it could drift with the game logic over the course of various game updates.

Given that you are already looking into the issue with the Loot Audit plugin, I don't think it's the right investment to add the sort-in-place feature to Sort Button at this time, unless more information can be provided to help justify the need for it. For now, you can disable one of the plugins to stop the lag.