In this video we will take a deep dive into optimising away heap allocations from our code. In previous videos we discussed garbage collection, which can have a huge impact on the performance of our algorithms, especially if the number of heap allocations is excessive. Today, we'll look at a practical optimisation example and try to improve a N-body physics simulation that aims to render in real time. We'll be able to clearly see how garbage collection impacts the performance of our simulation and then work to remove all allocations from our physics code - resulting in a much smoother animation.
If you are interested in learning more about this topic, below are a few links that you may find interesting:
https://www.youtube.com/watch?v=BFvpwC8hEWQ
https://docs.julialang.org/en/v1/manual/performance-tips/
You can find the code in the video in the GitHub repository linked below:
https://github.com/MPAGS-HPC-in-Julia/reducing-allocations-example
Timestamps:
00:00:00 Introduction
00:01:14 Case Study - Physics Simulator
00:03:20 Physics Simulation Code
00:04:28 Slicing Notation
00:04:57 Adjoint Operator
00:05:27 Broadcasting ("Dot") Notation
00:06:49 Benchmarking
00:09:56 Profiling Memory Allocations
00:16:05 Views
00:19:04 Preallocation
00:22:20 Broadcast ("Dot") Fusion
00:25:53 Optimising "acceleration" function
00:28:17 StaticArrays.jl
00:32:03 Simulation (No Optimisations)
00:32:37 Simulation (with Optimisations)
00:33:10 Outro
This module was designed as an MPAGS (Midlands Physics Alliance Graduate School) module and aimed at postgraduates and early career researchers.
Useful links:
Git/GitHub for Researchers:
https://www.youtube.com/watch?v=CuOmaUS1FnM
Course Information Website: https://jamiemair.github.io/mpags-high-performance-computing/overview/
Julia Documentation: https://docs.julialang.org/en/v1/
MPAGS Registration: https://warwick.ac.uk/fac/sci/physics/mpags/registration/
Course Notes: https://jamiemair.co.uk/courses/hpc