-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use slice instead of StaticArray for String::CHAR_TO_DIGIT #5616
Conversation
But requires a HEAP allocation. |
Is there any performance benefit (or something) over having this in stack? |
What does hits mean here? |
I meant "hits" as number of occurrences of CHAR_TO_DIGIT including CHAR_TO_DIGIT62 in outputted .ll file. But I now realized, that number depends on I use it or not, and how many times I used. |
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
By filesize
|
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. |
@ysbaddaden the previous code already had |
How to get optimized version of ll? |
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.
|
By using Pointer and Slice instead of StaticArray,
less LLVM IR generation for String::CHAR_TO_DIGIT (1054 hits to 76)