+= has been life changing.
do
local z = 1 + (a or 256)
freq[z] = freq[z] + 1
end
I wrote a script to convert my entire codebase to the new compound operators. The script is <100 lines but depends on a lot of other modules that do tokenization / lexing so it’s operator-priority-safe, but isn’t easy to share. It found 519 scripts and removed 22kb of source.
Anyways, here’s a quick multicore bench:
With batches of 64 the performance is pretty much identical. I had decided to skip \0 because it’s what we’re trying to escape and usually has a high frequency in uncompressed data.
It actually concatenates in batches of 64 because it takes over 2x longer to add to add each character to an array #data
long and concatenate it (even when the table is reused.)
It’s interesting that a + 1
takes 0.95x the time 1 + a
does (not controlling for everything else that’s being done.) In most languages it’s just preference but here we get slightly different instructions.
Perhaps someday we’ll get an instruction that takes the add out of a[b + 1] = c
. The addition probably isn’t much compared to converting from a double though
I’m just hoping that attributes will support \0 so I don’t need to use this at all. BinaryStringValue also seems like it would be a good alternative if it’s value was exposed.