Skip to content

ekahlenberger/rustyAlmonds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rusty Almonds

This project is a learning experience for me in understanding workload parallelization and window management using the Rust programming language. The main focus of this project is to leverage the power of Rust to create an efficient and highly performant Mandelbrot fractal renderer.

Libraries used

  • crossbeam: Provides the crossbeam-channel crate for fast and easy-to-use multi-producer multi-consumer channels.
  • winit: A platform-agnostic window handling library to create windows and handle input events.
  • pixels: A tiny hardware-accelerated pixel frame buffer for building 2D applications. Initially, I could not figure out how to use winit to draw to my window. Well, winit does not provide that functionality. The solution was to combine winit and pixels, which was a valuable lesson learned. Great library.

Performance Considerations

When optimizing the performance of a program, it's essential to understand both the problem domain and the programming language, as well as the models being used. This project leverages Rust's powerful concurrency model to achieve efficient parallelization of the rendering workload.

Problem domain optimizations

  • Early escapes for the main cardioid and period 2 bulb
  • Early escapes for periodic calculations
  • Optimizing the mandelbrot calculation away from the first naive approach
  • Gradient checking, escaping if changes are so small that escaping the Mandelbrot set seems implausible.

Language domain optimizations

Another optimization using Rust is to avoid copying results of thousands of pixels back into the main render thread. Instead, a heap-allocated Vector is used, and only a reference to the data is copied. This approach also helps avoid stack size problems. Crossbeam makes inter-thread communication really easy. Furthermore, in one of the first iterations, all the coordinates of pixels that had to be calculated were copied to the worker threads. Now, only the start value and the needed amount are copied.

Think about your problems, test your ideas.

Getting Started

Clone the repository and

cargo run --release # compiling takes time as lto is activated

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages