Use slice instead of StaticArray for String::CHAR_TO_DIGIT #5616
This is minimal code I used to generate .ll file in release mode
I see like following in .ll file
Comparing by line numbers in .ll file
The way LLVM generates code for static array is quite poor. But as I understand, the code is generated in a way that is easy to be optimized in the later phase. Perhaps you should compare the optimized version of the ll, or even the final optimized binary. Using heap here is clearly more runtime work and if it is better then staticarray is wrong all the way down.
The difference is that StaticArray (and Slices) is bound checked, but the changed code uses direct pointer accesses.
Keep the static array and skip the malloc but operate on
But you get unsafe code, and must be perfectly sure to never have out of bounds value.
I tried to compare in assembly dump, but I am not sure those really refer to CHAR_TO_DIGITS array, because every lines differ in comparison.
But I do see similar in objdump output too.
The core issue is StaticArray using a loop to fill a value to all items.
but I think those can actually done with one memset (for Int8 | UInt8) call for initialization.
EDIT: I tried to change StaticArray and used memset instead of Loop but that does not change the result, so
Not a typical usage, but doing an assignment on benchmark went a bit slower.