Arnas Puidokas

Graphics Programmer Portfolio

🏠 Home ⭐ Best Project 📁 All Projects 📰 All Blogs

Low-Level Platform Optimisation

by

Tags: C++ Performance Multithreading Optimisation

Overview

This project looked at low-level optimisation techniques such as memory management, timing optimisations and porting over to PS5. A custom memory manager system was implemented to track memory allocations, this included an allocation tracker, object creation and destruction, and a memory pool to reduce allocation overhead by reusing pre-allocated memory. Performance improvements were achieved through spatial partitioning, which split the scene and reduced collision checks. Finally, a multithreaded system was applied to this that allowed the regions of the scene to be checked at the same time.

Key Features

Memory Manager

Custom memory allocation tracking, object lifecycle control, and memory pooling to reduce allocation overhead.

Spatial Partitioning

Reduced collision checks by dividing the scene into regions.

Multithreading

Processed spatial regions in parallel to improve performance.

PlayStation 5 Optimisation

Explored low-level optimisation techniques for PS5.

Technical Breakdown

Memory Manager (Memory Allocation Tracker)

A custom memory tracking system was implemented to monitor object allocations at runtime. This was done through multiple tracker instances like box, sphere, and global (all objects), where each tracked their respective object type. The trackers managed their total allocation and deallocations of which objects were still using memory at runtime.


The first code shows what is inside the tracker class and some functions of it. While the second piece shows the trackers getting their own allocation of memory through malloc. (Figures are clickable)

Memory Manager (Erase Objects)

Objects were removed through the object's collider that was closest to the screen cursor upon getting clicked and removed from the all object vector. Initially there were threading issues when using "std::vector::erase"; however, by adding synchronisation to ensure all threads complete their tasks before deleting an object, this prevents race conditions from happening and any dangling pointers that would come.


This shows of the code that I talking about from above. (Figure is clickable).

Memory Manager (Performance Timer)

A simple timing profiler was added through "std::chrono" to measure the execution time of physics and the multithreaded systems. Data was accumulated over 60 frames to provide a more stable performance comparison between tests.


Memory Manager (Memory Pool)

To reduce runtime allocation overhead and avoid heap fragmentation, a memory pool was implemented to preallocate memory for game objects at runtime. Instead of allocating memory dynamically per object, objects are instead constructed using placement new from preloaded memory blocks within the memory pool. This system allowed memory to be reused from the pool and destroyed objects, enabling new objects to be created without repeated heap allocations.