You may know that I am contributing to the great vAmiga project since a while. Some improvements provided were for example a full MCP server to support controlling the Amiga Debugger in vAmiga. I also started to port the UI to Imgui, which is quite far and also the including the MCP server. You can find it here .
So, I was looking through the vAmiga source code the other day and spotted a funny comment in the FileSystem::format method: TODO: SPEED THIS UP. It was pretty obvious why it was there. The old code was basically checking every single potential block on a partition just to mark the free ones. Doing that meant running some really heavy operations for every block, like dynamic lookups in an unordered_map and shifting bits around to set the bitmap right. When you are dealing with gigabyte sized Amiga hard drive images, those calls add up into the millions and completely choke the formatting process. Dirk Hoffmann, the author wisely marked that in his source and put the challenge to the backlog for later iterations.
I made it my task to address this thing and figured there had to be a better way, so I completely flipped the logic. Instead of checking every block one by one, we just declare the whole thing as free right from the start using a bulk operation. Then we go back and mark the actual metadata as used.
The improvement breaks down into three simple steps:
- First we use
std::ranges::fillto mass assign the free blocks to 0xFF directly in the bitmap block payload. - Next we correct any phantom bits that sit outside the actual volume limits by marking them as used.
- Finally we manually flag the root and bitmap blocks as taken.
The difference is honestly night and day. Instead of doing millions of hash map lookups, we do one big fill operation that the compiler easily turns into highly optimized machine code. The math behind the scenes changes completely. The time it takes no longer grows with the partition size but stays flat based on the metadata.
My benchmarks really show off the difference. Formatting 524288 blocks used to take about 205 milliseconds. Now it takes a tiny 0.25 milliseconds. That old file system bottleneck is totally gone.
Like I said, I have been contributing to vAmiga for a while now, and it is always a great feeling to find little ways to support Dirk in his amazing project and make the emulator run even better. Every tweak helps us build a smoother experience, and I cannot wait to get this merged (It is already merged to the dev branch) and move on to the next challenge.
If you want to see the actual code and the full benchmark numbers, you can check out Issue 979 over on GitHub ( https://github.com/dirkwhoffmann/vAmiga/issues/979 ).