Welcome to the Optimization Workshop!
Your goal is to take a simple, unoptimized N-Body simulation and make it run as fast as possible.
The core of the simulation resides in NBodySimulationOptimised.cs. The Step() method calculates the gravitational forces between all bodies and updates their positions. Currently, it's a naive
- .NET 10 SDK or later.
- SDL2 Runtime: This project uses SDL2 for visualization.
- Windows: The required DLLs should be handled by the NuGet package, but if you encounter issues, ensure
SDL2.dllis in your path. - macOS:
brew install sdl2 - Linux:
sudo apt-get install libsdl2-2.0-0
- Windows: The required DLLs should be handled by the NuGet package, but if you encounter issues, ensure
To see the simulation in action:
dotnet run -c ReleaseThis will open a window showing 5,000 bodies interacting gravitationally.
To accurately measure the performance of your changes:
dotnet run -- --benchThis uses BenchmarkDotNet to provide high-precision measurements.
- Open
NBodySimulationOptimised.cs. - Analyze the
Step()method. - Apply optimization techniques to reduce the execution time.
- Verify that the simulation still looks correct by running it visually.
- Benchmark your changes to quantify the speedup.
Check out the CHEATSHEET.md for inspiration on techniques like SIMD, Multithreading, and Memory Layout optimizations.
Good luck!