Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lag in gamemodifier context application on all entities every tick #16

Closed
LemADEC opened this issue Apr 23, 2023 · 3 comments
Closed

Lag in gamemodifier context application on all entities every tick #16

LemADEC opened this issue Apr 23, 2023 · 3 comments
Assignees
Labels
1.18.X Related to Minecraft 1.18 1.19.X Related to Minecraft 1.19 bug Something isn't working

Comments

@LemADEC
Copy link

LemADEC commented Apr 23, 2023

As observed in CottageWitch 1.13.3 with majrusz-library-1919.2-3.3.0, there's a lag issue observed with Spark profiler.
This lags affects all entities when handling modifiers every tick. Specifically, handling of modifier takes 5x more CPU than just checking the enchantment level.

Upon code review, we can see objects are created every tick for every entity, which cause memory stress and lag, see: https://github.com/Majrusz/MajruszLibrary/blob/1.19.X/src/main/java/com/mlib/gamemodifiers/contexts/OnEntityTick.java#L26
=> consider passing the data without creating a new object?

We can see also a stream object created but hardly used here: https://github.com/Majrusz/MajruszLibrary/blob/1.19.X/src/main/java/com/mlib/gamemodifiers/Contexts.java#L29
=> consider exploiting more of that object or code without creating such object?

Profiler show also Stream API filtering is causing copy of objects.
=> consider removing filtering from Stream API level, or remove Stream API usage altogether?

An additional approach could be considered by "throttling": for example, apply effects only every few seconds since enchants are prone to change at most every few minutes, consequently we could throttle the update to only be done very 100 ticks (5 seconds).

@katubug
Copy link

katubug commented Apr 23, 2023

After doing some more testing, it seems it is only happening when the Enchantments mod is added. I ran a profiler with Accessories and Library and the memory leak does not seem to be present.

https://i.imgur.com/gfQe1Sw.png

@VallenFrostweaver
Copy link

Can confirm the above.

@Majrusz Majrusz self-assigned this May 28, 2023
@Majrusz Majrusz added bug Something isn't working 1.19.X Related to Minecraft 1.19 1.18.X Related to Minecraft 1.18 labels May 28, 2023
@Majrusz
Copy link
Owner

Majrusz commented May 28, 2023

Hi, I had a break from modding recently, so sorry for the late response, but thanks for the report. After I release changes made before my break, I will try to fix this as soon as possible

@Majrusz Majrusz closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.18.X Related to Minecraft 1.18 1.19.X Related to Minecraft 1.19 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants