Volker Schwaberow

Reducing Format Time in vAmiga Hard Drive Images

2 min read
Reducing Format Time in vAmiga Hard Drive Images

I have been contributing to the vAmiga project for a while. Previous work includes an MCP server for the Amiga debugger and an ImGui port of the UI, including the MCP server integration. The ImGui branch lives in vAmigaImgui.

While reading the vAmiga source, I found a TODO: SPEED THIS UP comment in FileSystem::format. The existing code checked every potential block on a partition to mark free blocks individually. Each check ran unordered_map lookups and bit shifts on the allocation bitmap. On multi-gigabyte Amiga hard drive images, that means millions of calls and a slow format path. Dirk Hoffmann had noted the issue in source and deferred it to a later iteration.

The fix inverts the approach. Instead of probing block by block, the bitmap is initialized as entirely free with one bulk operation. Metadata blocks are marked used afterward.

The change has three steps:

  1. Bulk fill Use std::ranges::fill to set free blocks to 0xFF in the bitmap block payload.
  2. Boundary correction Mark phantom bits outside the volume limits as used.
  3. Metadata blocks Flag the root and bitmap blocks as allocated.

The per-block hash map loop is replaced by a single fill that the compiler lowers to tight machine code. Runtime no longer scales with partition size for this step; cost stays tied to metadata size.

On 524288 blocks, format time was about 205 milliseconds before the change and 0.25 milliseconds after. The patch is merged to the vAmiga dev branch.

Source and full benchmark numbers are in vAmiga issue 979.