Re:Optimizing Ray Tracing in Haskell
by amelius on Saturday July 18, 2020 @09:01PM
(#23886127)
I certainly didn't expect it to be faster than the Rust implementation. Quite a surprise there.
[ Parent
| on HN ]
To be fair, the Rust program isn't yet optimized fully. We tweaked few things here and there, and the speed improved from 26s to 19s. I believe it can still be improved further. I'm sure it can get better (especially if the issues in Rayon crate are addressed). However, at the same time, I think even Haskell version can be improved further. I'll update the blog post, or might create new blog post, once I have some interesting data to share.
Re:Optimizing Ray Tracing in Haskell
by rainbow-road on Saturday July 18, 2020 @10:40PM
(#23886582)
To be fair, the first sentence on the Rust implementation's GitHub repo is
> A straightforward Rust implementation
(emphasis mine) and the implementation in the article is heavily optimized.
I don't think this Haskell implementation is heavily optimised per se. The only places where readability is sacrificed for performance is the use of INLINE and the custom tail-recursive function, which is not where most of the performance improvement comes from. The other improvements (an efficient RNG, an efficient vector representation, and extract strictness) are something you get by default in Rust.
I would say that if an experienced Haskell programmer set out to write this program with the intent of making it fast, they'd never use lists in the first place, and not consider their absence an optimisation. Haskell lists are designed for lazily-generated arbitrary-length sequences, and are a bad fit for representing small finite-length sequences, such as vectors.
Re:Optimizing Ray Tracing in Haskell
by CyberDildonics on Sunday July 19, 2020 @10:18AM
(#23889521)
The rust implementation has a lot that is very naive from a performance point of view. Every sphere is allocated separately on the heap, so every sphere hit would have to hop through that sphere's pointer.
There is actually a fairly simple C++ version that was made as part of the original book. It also does a lot that is naive from a performance standpoint, but that's what I would think people would want to use a baseline.