rtrace 0.1.0

A pet raytracer to test overall pseudo-performance and multi-threading
docs.rs failed to build rtrace-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rtrace-1.0.0

title

Trace Quest 5: Rise of an Empire

Following cinematic success stories such as The SHA1 Performance Quest, there is yet another quest for performance, seeking out benchmark results that no man has seen before !

It's stardate 20.15.01.31, in a universe ruled by nimble Gophers and ancient Ceepeporg, a universe where the production of RaySpheres™ is the only goal, the faster, the better. Meet the Rustaceans, a young species, and follow them on their curious quest for independence and for producing the most RaySperes in the universe.

How to run

Make sure you have gcc installed as well as go for the respective version. Then it's the following to produce images and time them. Please note that they will only use one core by default - the cpp version doesn't impelement multi-threading.

make -C src/go image
make -C src/cpp image

# Use more cores with go implementation to witness speedup
GOMAXPROCS=4 make src/go image

Lessons Learned

  • Instead of parameterizing primitive number types in generics, use a type alias instead. That way, the code is simpler overall, and you may use number literals in your code. This is viable if you just want to test how different number types will affect your runtime performance.
  • When using multi-threading, everything used by a thread needs to have static lifetime. To assure that, you can
    • create resources within the thread, handle them and send a particular result through a channel.
    • pass in read-only shared resources through an Arc. The latter is a reference counted item on the heap.
    • pass writable resources through an Arc<Mutex<R>> to allow synchronized access.
    • Yes, it's not currently possible to signal a resource is safe for use if allocated on a stack and protected by guards that will assure the resource remains alive during the thread runtime.

Original Credits

The go based raytracer was originally written by Jack Palevich. For more information, see http://grammerjack.blogspot.com/2009/11/multi-threaded-go-raytracer.html.