News for hackers. Stuff that matters.
Re:Show HN: I wrote a C++ ray tracer from scratch without AI by pixelesque on Monday June 15, 2026 @10:58AM (#48542248)
Yeah, passing std::shared_ptr by value in a multi-threaded setup can have a lot over overhead due to them being copied and destroyed a lot, and the fact that the atomic ref count value modifications effectively cause a write back to cache and can cause contention.

Should pass them by const refs really to avoid this.

Re:Show HN: I wrote a C++ ray tracer from scratch without AI by cyber_kinetist on Monday June 15, 2026 @11:20AM (#48542597)
Or for a better alternative, just use plain old indices rather than shared pointers.

The scene is only going to be loaded / unloaded all at once, you can just load the data into contiguous arrays and index from them. No need to use shared_ptr since lifetimes aren't that complex.

Re:Show HN: I wrote a C++ ray tracer from scratch without AI by pixelesque on Monday June 15, 2026 @11:52AM (#48543100)
Or just raw pointers, indeed.

std::shared_ptrs can also (because they're implicitly for sharing) alias, so the compiler has to assume the worst and emit loads in other cases, and there's no way (unless a newer C++ version has introduced it and I haven't noticed?) to use '__restrict__' with shared ptrs.