actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
439 stars 95 forks source link

Performance while debugging #259

Closed thewhitegoatcb closed 1 year ago

thewhitegoatcb commented 1 year ago

Hello, I have compiled lua-debug with luajit(nogc64) of this commit: https://github.com/LuaJIT/LuaJIT/tree/a44f53acf53603e7d9b88352de035b1804be4e88 as the later commit has breaking features of the game im trying to debug(table ordering issues). The debugger works fine, everything is stable but the performance is about x50+ times slower than running without a debugger. Is it normal or im missing out on some massive performance on not using the later luajit builds or using your modified luajit fork ? P.S. I cannot easly test commits that are past the one that I linked

thewhitegoatcb commented 1 year ago

Update: Managed to update to the current modded luajit fork from this repo. Performance is still bad, things I observed: When attaching with "stopOnEntry": false, and no breakpoints set, the performance is good but as soon as I pause execution and continue or set a breakpoint anywhere, it slows down badly from capped 60fps to 1~ fps, it recovers if I remove the breakpoint. Jit is set to off by jit.off() early before the debugger and never on after compiled with LUAJIT_DISABLE_GC64, LUAJIT_TEST_FIXED_ORDER=1, LUAJITSECURITY* = 0 Is that normal ?

actboy168 commented 1 year ago

@fesily

fesily commented 1 year ago

Does this happen in functions of any size?

thewhitegoatcb commented 1 year ago

Does this happen in functions of any size?

just tested anything from 2-50~ lines functions, local funcs, table member funcs, all seem to cause slow downs also pulled the lasts patched luajit, same performance as from the current on this repo could the LUAJIT_DISABLE_GC64 cause any issues? im using it for bytecode compatibility of the already compiled scripts

thewhitegoatcb commented 1 year ago

No idea if it could hint at what's happening but all C functions with function_name seem to give off a wrong name image Address provided by tostring is correct

fesily commented 1 year ago

LUAJIT_DISABLE_GC64 I have not tested it, I'm not sure if it's because this flag is enabled.

fesily commented 1 year ago

You can provide a minimal test case, let me try

fesily commented 1 year ago

Or you can provide a flame chart, and let's check which code is running slow

thewhitegoatcb commented 1 year ago

I will try to produce one in the next few hours, unsure if just a small test case would be representable but I didn't try

thewhitegoatcb commented 1 year ago

image

image

Captured 16 secs with xperf, 15.6s out of 16s of the main thread is occupied by hookmgr::full_hook_callback This is with one breakpoint active.

thewhitegoatcb commented 1 year ago

Had another go, image This is gsub being called a LOT of times (about 1k times ~ per sec) from normalize_win32 in backend\worker\filesystem.lua.

I think I should clarify of the Lua environment of the game: The game has compressed file packages with compiled luajit scripts, they are being uncompressed and loaded by the game via luaL_loadbuffer. The files contain debug info with the relative script file path like scripts/unit_extensions/health/lure_health_extension.lua, to be clear the file doesn't actually exist on disk.

The game replaces require,dofile,loadfile with their own version to look for the scripts in the compressed packages. Currently I override some scripts that are being executed from these packages with files on disk by calling the original require,dofile,loadfile, There I place the breakpoints and able to debug fine (except the performance)

fesily commented 1 year ago

Try use the flag: pathFormat=linuxpath or sourceFormat=linuxpath

thewhitegoatcb commented 1 year ago

Try use the flag: pathFormat=linuxpath or sourceFormat=linuxpath

Tested any combinations of those, fully restarting the game for each test. Setting any of those causes BP not to trigger at all, and still lags. If I only set pathFormat=linuxpath and try to remove the BP ,the performance doesn't recover and still lags til I disconnect the debugger. I'm setting these in the launch.json

fesily commented 1 year ago

Fine, I will try to fix

thewhitegoatcb commented 1 year ago

Fine, I will try to fix

Thanks, let me know if I need to do test, or more profiling. Is there a way for me to debug lua-debug itself ?

fesily commented 1 year ago

only print when debug lua-debug. I downloaded the game, how do I start the debugger in the game?

thewhitegoatcb commented 1 year ago

only print when debug lua-debug. I downloaded the game, how do I start the debugger in the game?

The game doesn't have it's own debugger, im using my own project to start and load the debugger