gm_microoptimisation_war_crime icon indicating copy to clipboard operation
gm_microoptimisation_war_crime copied to clipboard

You mentioned dead code elimination not being done by LuaJIT

Open VaasKahnGrim opened this issue 3 years ago • 1 comments

So regarding DCE, I've never heard the term but I'm going to assume it basically would be dropping code that would logically NEVER be ran at all.

You mention it doesn't get performed by LuaJIT in this case, would it be very difficult to get the preprocessor here to instead of changing SERVER / CLIENT to true / false, have it perform an outright DCE itself? I'd imagine it being similar results(maybe slightly better numbers give that theres not a local or global look up at all anymore, and dead code wouldn't exist at all anymore. I have no clue if the deadcode would be loaded but not used or if it would cause some small impact. I know removing it would mean less memory usage if the dead code was dropped however.

Like for custom built servers that use only their own stuff it likely won't be much of a differance(I'd imagine smarter servers doing this would make sure to not use SERVER / CLIENT much at all), but on say your average darkRP server running a ton of workshop and gmodstore scripts, it could probably free a good chunk of memory. Some imaginary numbers just for a guess here, but say dropping from 300-400 MB down to 250-350MB, depending on how bloated the server is?

I mean its likely not much noticable but for sake of micro-optimization, I figured I'd atleast bring up the idea of doing that and get your thoughts on it and if it would be worth attempting for doing.

VaasKahnGrim avatar Feb 05 '22 18:02 VaasKahnGrim

Yeah it's definitely possible. If the module used a lexer + parser to build an AST of the script, that could be used to snip out branches for DCE.

WilliamVenner avatar Feb 05 '22 18:02 WilliamVenner