Skip to content

Performance boost: ADFS new-map bitmap index for O(1) fragment lookups#47

Open
philpem wants to merge 2 commits into
geraldholdsworth:mainfrom
philpem:perf/adfs-bitmap-index
Open

Performance boost: ADFS new-map bitmap index for O(1) fragment lookups#47
philpem wants to merge 2 commits into
geraldholdsworth:mainfrom
philpem:perf/adfs-bitmap-index

Conversation

@philpem

@philpem philpem commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

These performance improvements are mostly helpful on ADFS hard drive images.

Summary

  • Byte-at-a-time terminator scan in NewDiscAddrToOffset: replaces the original bit-by-bit loop with a 3-phase scan (align to byte boundary, skip zero bytes 8 bits at a time, scan last byte). Reduces ReadByte calls by up to 8× per fragment entry on large discs with big LFAUs.

  • Pre-built bitmap index (BuildADFSBitmapIndex): scans all zones of the ADFS new-map allocation bitmap once at disc-load time and stores results in FBitmapIndex[fragid]. NewDiscAddrToOffset then serves reads via a direct array lookup (O(1)) instead of scanning all nzones zones for every file (O(nzones × files)).

On a 4 GiB ADFS HDD image with 126 zones, the old code spent 3 minutes loading because every fragment lookup triggered a full 126-zone bitmap scan. After this change the same image loads in 26 seconds. The FBitmapIndex fast path is used only for offset=True (read) calls; write paths (offset=False) retain the zone-scan slow path unchanged.

This was created with Claude Code.

claude added 2 commits June 21, 2026 14:32
Replace the bit-by-bit terminator scan with a three-phase byte-aligned
scan. For large disc images with LFAU=8192, a single fragment entry can
span thousands of zero bits; skipping whole zero bytes gives up to 8x
fewer ReadByte calls in the inner loop.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012c5TpXWmyNtRKUpEUR6pUK
Before this change, every call to NewDiscAddrToOffset scanned all nzones
zones of the allocation bitmap to find entries matching the target fragment
ID. On a 4 GiB disc with 126 zones, loading thousands of files caused
O(zones * files) total bitmap scans.

BuildADFSBitmapIndex scans every zone once at disc-load time and stores
the results in FBitmapIndex[fragid]. NewDiscAddrToOffset then serves
reads via a direct array lookup (O(1) per call) instead of a full scan.
The slow path (offset=False write paths) is unchanged.

This eliminates the dominant term in load time for large ADFS HDD images.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012c5TpXWmyNtRKUpEUR6pUK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants