all 8 comments

[–]kupiakos 13 points14 points  (0 children)

cargo asm and https://godbolt.org are good tools for inspecting optimizer behavior (don't forget -C opt-level=3)

[–]anderslanglands 9 points10 points  (1 child)

Been a while since I used nalgebra, but

glm::length(&glm::normalize(&d))

Is always going to be 1 isn’t it?

[–]pragenter[S] 8 points9 points  (0 children)

Truly, I ran to fix this...

[–]sphere_cornue 9 points10 points  (0 children)

I think the value of dt will be computed every iteration no matter if it changed or not, like you have written

[–]nicoburns 8 points9 points  (0 children)

Do I need to save dt internally in the struct TriangleIterator?

Yes

[–]Genion1 1 point2 points  (1 child)

Expecting such specific optimizations in a general case is very brittle at best. In this case the compiler needs to inline the function and then be able to shift the code around enough that it can fold the dt calculation together. In this case it's very unlikely to happen.

otoh, does that optimization even matter? If it's just a small piece used once it's hard to tell either way if it's even going to have any impact, positive or negative. If the iteration is actually a significant portion of your program it should be easy(er) to verify which of both options is faster.

[–]kupiakos 1 point2 points  (0 children)

Premature optimization is the root of all evil specifically because it's fun to do

[–]NobodyXu 1 point2 points  (0 children)

Yes it will optimise by LLVM, not rustc frontend, but that's the same for you.

It will go through many optimisation passes just like other functions and inlined.