Natives performance
See original GitHub issueHi,
I’m developing a custom vehicle camera mod, and after doing some performance tracing, looks like calling natives is pretty slow.
Looks like each native call is taking around 26ms/40ms… Calling a few of them each frame hurts performance. Natives like e.g. checking if the player is in a vehicle.
Looks like this line is the responsible.
So, each time I call a native a task is created, then it waits some time (I guess for thread sync stuff but I don’t know) and then gets executed. Of course synchronously, and blocking the whole script.
But a few lines above, i see this:
if (Thread::CurrentThread->ManagedThreadId == _executingThreadId) {
task->Run();
In this case, task execution should be faster I guess, but my code doesn’t do it in that way.
Is there anything that I can do to make my script to perform better? Especially when dealing with natives, I mean.
Is coming any update of SHVDN 2.9.x that would improve natives performance? It’s ‘fixable’, or just not possible?
Thank you for your work 👍
Issue Analytics
- State:
- Created 6 years ago
- Comments:31 (8 by maintainers)
Top GitHub Comments
Hi! We noticed this same issue while working on GTMP way before this Github issue was made and started thinking about possible solutions (aside from the hacky native grouping workaround mentioned in this thread). So I started working on an experimental fork. I’ve wanted to post my fork for SHVDN as soon as I saw someone else having the exact same issues, but we wanted to wait until I got GTMP working stable on it.
I left (or currently taking a long break) from the GTA modding community, so I’ve decided to open source my fork (actually a complete rewrite of the C++ core).
SHVDNPro: https://github.com/codecat/SHVDNPro
Thus far, early results with our in-house profiler are showing a performance improvement of 14 times the framerate of regular SHVDN while in the GTMP main menu (which is @Guad’s TabMenu in NativeUI) but I believe this can definitely be improved a lot more.
This fork should work fine for most mods. We’ve had a few stability issues with GTMP that made the game crash, but I tracked that down to having something to do with our Clearscript/v8 implementation (looks like something isn’t resolving the library paths correctly or something, so that should be a relatively easy fix).
I’m Miss#4192 on GTMP’s Discord if anyone has any urgent issues or questions with this.
For those who wondering if SHVDN uses a trick with TLS by swapping the TLS pointer on the fly like RAGE Plugin Hook does, #1172 makes SHVDN use it and the PR improves performance as there’s no need to thread switching just for a single native call no more.