Applied Energistics 2

Applied Energistics 2

156M Downloads

Client View Sorting by Name Causes Lag

MidCoard opened this issue · 0 comments

commented

Describe the feature

I have a big AE network system in my server.
And when I open the terminal of the system, I sometimes feel the obvious lag, which even makes the client stop.

One time, I use the spark mod to profile it.
This is the log: https://spark.lucko.me/1bwYv1a9Fg

From the log, the client has spent most of the time in the sorting.
I have read some of the code and done some debug work.

It seems like that when the items in the AE system changed, the server will cause all the clients who are in the view to update. Changes to each item will result in an update and sorting. So when the network system is changing all the time, the client will update and sort all the time. This maybe why there will be an obvious lag.

because of 20 ticks in one second, the AE network system can be updated up to 20 times in one second.

And also, I have added some code in the Repo class
image
the sout part to record the sorting time and count.

I have found one thing is that when i select the sorting mode by amount
CCA1F13385845622FE3478445D6C6171
the sorting time is 1ms or 0ms

but when i select the sorting mode by name or others
9998FBFE61039CB8AF247E1139FE7F94
the sorting time is 50ms

because of 20 ticks in one second, each update and sort has spent the whole time, so the client feel the obvious lag.

So I have looked the detailed part of the log and read the name comparator code.
When name sorting, the getDisplayName method always create a new ItemStack to get its display name(in item part) .
image
the copyTag method and the new ItemStack instance have spent most of the time.

Solution:

  • 10 ticks for one update or it can be edited in the config file.

  • the AEItemKey class should have one field to store its display name to avoid calling the copyTag method and new ItemStack instance frequently.

the environment: fabric 1.18.1

Reasons why it should be considered

When there is a big AE network system and we want to sort by name, big client lag really makes the player sad :( 😭

Additional details

No response