question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Natives performance

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Comments:31 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
codecatcommented, Jul 7, 2017

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.

0reactions
kagikncommented, May 22, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local Natives - Full Performance (Live on KEXP) - YouTube
http://KEXP.ORG presents Local Natives performing live in the KEXP studio. Recorded May 17, 2019. Songs: When Am I Gonna Lose You Megaton ...
Read more >
Local Natives - Sunset Sounds Rooftop Performance (Live in ...
We're excited to announce a very special performance next Thursday, May 11. We'll be playing at sunset, on Sunset Blvd, from @neuehouse7869 ...
Read more >
Local Natives - Full Performance (Live on KEXP) - YouTube
http://KEXP.ORG presents Local Natives performing live on KEXP from The Triple Door. Recorded April 26, 2013. Songs: Breakers Ceilings Wide ...
Read more >
Local Natives Perform 'When Am I Gonna Lose You' - YouTube
Local Natives took the stage to perform one of Ellen's favorite songs of ... 'I Wanna Get Better' 360° Bleachers Performance | MTV...
Read more >
Local Natives - Full Performance (Live on KEXP) - YouTube
http://KEXP.ORG presents Local Natives performing live in the KEXP studio. Recorded September 20, 2016. Songs: Past Lives Coins Wide Eyes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found