How to profile Lua code to find bottlenecking code

Discussion in 'Programming' started by angelo234, Apr 7, 2021.

  1. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    Anybody know how to profile Lua code to find bottlenecking code?
     
  2. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Whow, this could be simple or very complicated. My best guess is to work with 'stages' of code, so you can isolate them to see what they perform individually and then carefully start combining them. Then there is the possibility to print stuff to the console, so you can 'gauge' the output. I've tried using a LUA editor (zero brain) before to analyze LUA code but that doesn't really works since the LUA environment in BeamNG is totally different from a 'raw' LUA distribution. It's totally 'sandboxed' (ok, not totally but..) and consists of 'Beam brew architecture' all over the place :D
    In the vanilla game code you sometimes find functions (made by the devs) too to serve analytic purposes.

    Anyway, the way I go mostly is keep my code in segments so I can enable and disable in different combo's and I print stuff to the console to see what is the output.
     
  3. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    Yeah the best way I found to "profile" the code was to do that staging method. But I did find a way to actually profile the code which was using the "LuaProfiler" module. But the LuaProfiler didn't actually help much because it claimed that similiar running code (I was converting my GameEngine Lua code over to Vehicle Lua code for a mod) in Vehicle Lua and GameEngine Lua both executed under a millisecond. But for some reason, running the code in Vehicle Lua would lag the game entirely (10 FPS) but running it in GameEngine Lua would only lag the game slightly (60 FPS). And so I decided to make the mod execute code in both GameEngine Lua and Vehicle Lua for performance. But I'm still not sure why one Lua environment bogs the game down so much but not the other.
     
  4. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    I didn't know this exists :) I follow my own device and instinct anyway ( just make something and test :) ).
    About GElua and Vlua, the vehicle loader underwent a total transformation only a few versions ago and yeah, I take it you are quite handy in this field so.. a lot depends on your own conclusions :) I just put the stuff where it works best, there's often many many different ways to make something work, it's quite amusing sometimes to discover that :)
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice