Jump to content

Recommended Posts

Posted

Hello, this may sound like a basic question, but I would love to hear about how you optimise your mods performance?

 

For example, I may be paranoid, but something about using event handlers that are called every tick does not sit right with me... does firing 10-20 different events cause much lag? even if there is very little to no logic happening every time?

 

I have a 'token' which amplifies the damage you do to mobs and the damage you take from mobs. The only way I could work out how to do this is to subscribe to the 'onEntityGetHurt' event and check if the player is holding the token. This means that  the actual logic for the item is in the event handler class and not in the item class. Is this bad? My code works, but sometimes I can't shake the feeling that my solution is... hacky.

 

Essentially my main questions are:

  • Does using events that fire every tick cause much lag? even if you have if statements so it only does something under certain circumstances.
  • Is it bad to have the bulk of item logic in the event handler and not in the corresponding item class?

However, I am also interested in hearing any other tips you have? I don't want my mod to cause unnecessary performance drops.

 

Thanks in advance,

Sam

Posted

Obviously, if you can avoid using a tick event, for example because the Item class already has #onUpdate which you can override to do things on a tick-by-tick basis, then avoid it. But if a tick event is the only way to make your mod work, then go for it - as long as you don't overdo it (avoid nested loops and recursive calls as much as possible) it has negligible impact on performance.

 

And yes, you shouldn't be putting most of your Item code in event handlers rather than the Item class itself, but depending on what you are trying to do, this may be unavoidable.

 

LivingHurtEvent is a good example - you can't use the Item AttributeModifiers since I assume the Item is not held or equipped while doing damage, so that event is really the only way you can apply your damage bonus. That's perfectly fine, especially since it sounds like you are setting up your logic to break out early and avoid processing when not necessary, which is the best you can ask for.

 

Basically: events are already pretty optimized and, in comparison to everything else that is already going on in Minecraft, require negligible processing power UNLESS you do something stupid in there ;)

Posted

Anecdote:

I remember when I stared coding stuff that heavily changed how mobs act.

Since I "come from" performance-oriented programming I was packing literally everything into generic types and operated on some weird-ass ticking (e.g not 20/sec but every 5 or cache-based stuff).

The mod itself was applying properties to every living enitity which on server reaches probably above 5000 spawned (depending on loaded area).

Using generic data and those caching systems - sure that gave me few MB RAM and maybe little part of tick, but hell - never again.

 

Seriously, as the mod expanded to current version I rewritten everything to object-oriented systems, also I no longer care about per-tick operations.

You would have to do some pretty HEAVY stuff to actually slow the game.

As of now I probably hold about more than few houdred objects per entity and do pre, mid and post tick on each of them, updating their effects, casting status, some party/guild stuff, literally everything.

On top of that I have tons of world- and server-based operations handling quests and shitload of who-knows-what.

 

Result? Hell - the mod takes next to nothing in means of performance (close to vanilla forge) and about few dozens of MB ram more.

 

I hope this will give some view on "how to not care".

 

Just note: I am not talking "don't ever care" - you should, just don't do too many micro-optimizations.

 

EDIT:

From all of bad pieces of code I've seen - most of them fail on:

* Not caring what happens interanally (e.g: calling methods that have no idea what they "actually" do), just take setBlockState - it also updates light in world if you don't use it properly.

* Recursion

* Retarded usage of if statements (seriously, order is important).

1.7.10 is no longer supported by forge, you are on your own.

Posted

Minecraft performance does not seem to be limited by server-side "thinking". Nor is it (given a decent graphics card) hampered by rendering. Instead, the bottle-neck seems to be client-server communication. Bandwidth is crucial (especially for some home-hosted servers with residential connections), but ill-considered design can also run afoul of round-trip time (especially if multiple round-trips are required to coordinate a decision and its effect).

 

So be aware of the things that introduce bandwidth and round-trip delays. For example, tile entities can. It's okay to have them for truly special block devices, but you wouldn't want to replace all of the stone in the world with something generating a packet on every tick  :o

 

In general, if you can wrap your head around client-server software design (and if you have decent client hardware plus server bandwidth), then you shouldn't have any performance problems.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.