garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

A few string lib optimizations

Open thegrb93 opened this issue 3 years ago • 4 comments

thegrb93 avatar Jun 25 '21 06:06 thegrb93

Didn't know string.gsub was faster than str:gsub

mcNuggets1 avatar Jul 04 '21 14:07 mcNuggets1

yeah can we see some benchmarks on that?

TomDotBat avatar Jul 04 '21 15:07 TomDotBat

yeah can we see some benchmarks on that?

It's intuitive. str:x will call __index then the method as opposed to str.x which accesses the method directly (though both do string table lookups every time as opposed to localising which is even more efficient). You can see this difference clearly in the output bytecode, even with JIT. It's too few cycles for benchmarks to be as useful of a tool in measuring gain, but I'm sure at enough indexes it will become noticeable enough.

These changes are all included in https://github.com/Facepunch/garrysmod/pull/1407 too.

Kefta avatar Jul 05 '21 12:07 Kefta

@Kefta only thing missing is the regex updates here. I have them in starfall at least until whenever devs decide to accept PR code

thegrb93 avatar Jul 05 '21 13:07 thegrb93

I have undone some problematic changes (https://github.com/Facepunch/garrysmod/pull/1812/commits/32810d5b9ad694406fcb15f0e1e759eb001c8090)

robotboy655 avatar Jan 17 '23 15:01 robotboy655