PRO will go

Ok, parameter reference optimization in Zig will soon leave this planet.

So mostly I will use *const for my struct parameters.

But in a lot of cases (Rect, Point) I just put that one in without *const.
That would uglify my code.
In these functions I do nothing but read them.
What happens in that case?
As I vaguely understand: if the compiler can proof the function is “clean” it will still use a referenced parameter.
Is that true?

For small structs, like Point, it’s faster to pass by value.

Yes, that’s true. It’s not implemented yet, and it’s unclear how effective it will be. There’s no reason why C couldn’t implement the same thing. As far as I know, C doesn’t do this optimization, which is a sign that this is a very difficult problem.
I suggest just forgetting about PRO and always assume that the compiler will follow exactly what you told it to do.

4 Likes

Aha ok. good to know small structs is faster. I did not know that.
(edit: except i did for sizes until u64 on my 64 bit machine)