Does `-O3` affect heaptrack analysis?

I hope to optimize the program as much as possible while ensuring that the analysis in Heaptrack is as thorough and accurate as possible.

Thanks in advance.

It will affect it but not significantly, the debug symbols are the most important part to keep, -03 might not include them but you can include them explicitly then.
Allocations can’t be hidden/removed by the compiler easily.

I think that’s the default compilation option for kde-builder, release with debug symbols.