Performance boost: ADFS new-map bitmap index for O(1) fragment lookups#47
Open
philpem wants to merge 2 commits into
Open
Performance boost: ADFS new-map bitmap index for O(1) fragment lookups#47philpem wants to merge 2 commits into
philpem wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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). ReducesReadBytecalls 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 inFBitmapIndex[fragid].NewDiscAddrToOffsetthen serves reads via a direct array lookup (O(1)) instead of scanning allnzoneszones 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
FBitmapIndexfast path is used only foroffset=True(read) calls; write paths (offset=False) retain the zone-scan slow path unchanged.This was created with Claude Code.