is it safe to assume that big_arr_1 and big_arr_2 will also be allocated on the heap?
i’m asking because, i’m getting massive FPS drops if those two arrays are specified with a compile time known length
whereas allocating them at runtime with an allocator removes those FPS drops.
i don’t know the exact source of the FPS drops, i just know that making one change, which is runtime allocating those arrays, solves those FPS drops.
Arrays in zig are not secret pointers, unlike some languages cough c cough, they are the full memory as a value.
Since you are allocating the struct they are in, yes they will be on the heap at runtime.
I think you are talking about using slices, which don’t have a comptime known length. In both cases they are heap allocated at runtime.
Can you share the code where you use them, ideally the code that causes the issue if you can narrow that down?
And what zig version are you using?
Unnecessary memory copies are the likely cause, zig used to have a bug where it copied arrays when indexing, but that should be fixed. It’s also possible that you have code that is copying them when it shouldn’t be.
those are the only uses of those two arrays, everything else calls those funcs to get or set elements, right now the arrays are runtime allocated as well as the struct itself, so those funcs are built with that in mind
Check the assembly to see if it’s copying the whole array, godbolt is good, but it’s a website so it’s not useable unless you can reduce the code to something small.
There are various tools to see assembly locally, objdump is what I use on linux, its usually preinstalled or comes with other dev tools.
Debuggers also typically let you see assembly.
Its also worth asking what optimise modes does the slowdown occur on, its still worth reporting regardless, but you could work around the issue by using a different mode. If your using debug on x86_64 linux, then you’d be using the custom backend which has less optimal output, but faster to compile, you can force the use of llvm in the exe/lib/etc options.
Oh no, this was straight up copied from my source code.
fetchUpdateLight is used in the program, so it’s not being ignored.
ill make a bug report with a reproducible code soon
EDIT: ^ this only works on heap allocated slices, on arrays, the compiler knows its a constant and throws an error
i don’t really know how to read asm, but i got a minimal asm code of the relevant functions using -fstrip and -O ReleaseSmall, this is with the arrays set with comptime known length
You’re sure the callsites are in turn used, so the function is actually analyzed? I have very similar code using rmw, and making the pointer argument const gives me the expected “cast discards const qualifier” error on master (just pulled today). 0.15.2 gives the same error on that code.
The difference between your and my own code, is that you have slices in the fields and I use arrays, so there’s one more level of indirection in your case. So it’s probably fine.
the array version probably mixed us both up, as that one would be a problem. Ofc slices are pointers, and have their own constness.
Speaking of, if the data is in slices, then Op probably wouldn’t need to heap allocate the struct. Idk if they were doing that, but I figured I should point it out.
You don’t have to write out std.builtin.AtomicOrder.acquire, just .acquire will do (and is idiomatic).
A parameter is a result location, so the compiler will try to cast .acquire (an enum literal) to a std.builtin.AtomicOrder (an enum). No need to localize any names, it Just Works.