Sort Button causes LAG

When people press the sort button on a box they did not create/place it causes lag to the server, other people on my server have noticed this too

Which version are you using? 2.x is very optimized compared to previous versions, so I wouldn't expect any lag. My benchmarks of this plugin haven't found any issues.

Players explicitly detecting server lag is  very surprising. Usually an operation needs to take many milliseconds to have a noticeable impact on server performance, and sorting should generally be well under a millisecond. Have you confirmed that what players are seeing is in fact server side lag, not client side lag? Players and server owners are often not well educated on the differences and therefore often mislabel one type of lag as another. Have you measured this lag spike use any performance profiler to determine how much the server frame time is increasing?

Assuming you are correct that players clicking the sort button is causing server side lag, we will need to determine precisely which circumstances cause it. For example, what types of items are in the container? Weapons, attachments, deployables, clothing, components? If you can determine whether certain types of items cause more lag, that will be useful for the investigation.

Off the top of my head, the main reason that clicking the sort button could affect server performance is the fact that it removes all the items from the container, sorts them in a list, then adds them back to the container. Items which have associated entities, such as weapons, could trigger network updates when being moved. Items being added to and removed from the container can also call hooks which many other plugins may be handling, therefore compounding the problem if you have many plugins like that, especially if those plugins are not optimized. This is definitely an area that the plugin can improve on, by sorting the items in place in the container. Such an optimization will initially come with the downside of not consolidating multiple stacks of identical items, but we can work on a solution for that as well.

I am using the most recent updated version.

I just wiped the server so i cant make a video right now to show you. the type of stuff inside the box is all random so i cant be more specific right now but i can explain what happens

I look inside someones box > I press sort (N or C) > lag occurs > unable to open doors, unable to open inventory, unable to Vanish but i can noclip, soon as i go "X" Distance away from the box everything becomes normal again. but normal users cant noclip away so they end up getting kicked by the server.

Just wiped the server so soon as it becomes populated ill try to replicate it

I see. The N and C buttons save the data file that stores player preferences (the plugin remembers whether each player prefers to sort by Name or Category). Previous versions of the plugin would produce a very large data file because they would save a preference for every user. V2 produces a much smaller data file by only saving the preference if different from the default. The issue is, if you already have a large fata file, the plugin won't clean that up. Please check on the size of the oxide/data/SortButton.json file to confirm that it is large, then unload the plugin, delete the data file, and reload the plugin. Some players will need to configure their preference again, but the data file will generally grow at a very slow rate moving forward, vastly reducing the lag caused by players changing their preference. This should resolve the lag issue you are seeing.

If desired, we can make further optimizations in the plugin, by saving the data file on a schedule rather than saving it every time players change their preference. That prevents players from causing load by changing their preference frequently. 

seems to have sorted itself out after the wipe. i feel like thats becoming more of a problem after plugin updates, i update, follow the instructions if any like delete data/config/lang and so on then add the update and things are still broken until a wipe happens

@WhiteThunder Another way to clean up the data file is to check (when loading the plugin) if the saved data is different from the default values, and delete it if not. This optimizes the file size, but may result in loss of user data if the administrator frequently changes the defaults.