Unaligned access trade-offs for SFrame FRE layout
Steven Rostedt
rostedt@goodmis.org
Mon Sep 15 16:04:00 GMT 2025
On Sat, 13 Sep 2025 00:56:34 -0700
Indu Bhagat <indu.bhagat@oracle.com> wrote:
> I think quantifying the performance impact of unaligned accesses for
> stack tracing using SFrame sections will be larger experiment which will
> be hardware dependent..
>
> https://lemire.me/blog/2012/05/31/data-alignment-for-speed-myth-or-reality/
I'm not so sure his example is good enough to show the overhead. So I wrote
a much simpler test. I create an array of 1,000,004 unsigned longs and fill
it with a simple increment.
I then loop over the array and reading at every 5618 increments and modulus
it to 1,000,000. I use 5816 because it is a factor of 1,000,004. By
incrementing it by this number and modulus it with 1,000,000, then the wrap
will go to 1,000,000 + 4. meaning by looping a 1,000,000 times on a
1,000,000 words should hit all of them if they are 4 byte long words or
half of them if they are 8 byte words.
I time a loop of going over all 1,000,000 numbers and simply adding them. I
then report the total time.
The test takes an offset to add before reading. Here's my results on two
machines:
On my workstation: Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
$ ./aligned-access 0
val = 2296870857426500744
time = 6822 us
$ ./aligned-access 1
val = -2296870857426996608
time = 7319 us
$ ./aligned-access 2
val = 2296870857426500744
time = 7432 us
$ ./aligned-access 3
val = -2296870857426996608
time = 7522 us
$ ./aligned-access 4
val = 2296870857426500744
time = 6841 us
On my server: Intel(R) Xeon(R) CPU E5-2683 v3 @ 2.00GHz
$ ./aligned-access 0
val = 2296870857426500744
time = 7093 us
$ ./aligned-access 1
val = -2296870857426996608
time = 6948 us
$ ./aligned-access 2
val = 2296870857426500744
time = 6761 us
$ ./aligned-access 3
val = -2296870857426996608
time = 7111 us
$ ./aligned-access 4
val = 2296870857426500744
time = 6940 us
$ ./aligned-access 5
val = -2296870857426996608
time = 6939 us
$ ./aligned-access 6
val = 2296870857426500744
time = 6937 us
$ ./aligned-access 7
val = -2296870857426996608
time = 7254 us
$ ./aligned-access 8
val = 2296870857426500744
time = 6939 us
My workstation is a bit older than my server, and it looks like alignment
does make a difference. For my server, it didn't show any difference.
Thus, it looks like it's only a problem for older machines (on x86). Would
be good to see how the performance of this is on arm64 machines.
But feel free to try it out yourself.
-- Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aligned-access.c
Type: text/x-c++src
Size: 1948 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20250915/f9aa658e/attachment.bin>
More information about the Binutils
mailing list