Skip to content

Use memory mapping to read files - #50

Merged
sirbrillig merged 3 commits into
trunkfrom
add-memory-mapping-read
Mar 15, 2026
Merged

sirbrillig merged 3 commits into
trunkfrom
add-memory-mapping-read

Conversation

@sirbrillig

@sirbrillig sirbrillig commented Mar 15, 2026 •

Copy link
Copy Markdown
Owner

This PR switches file reading (during prescan and main scan) to use memory mapping. We use the memmap2 package which memory-maps a file, meaning the OS maps the file's contents directly into the process's virtual address space. Instead of calling read() to copy bytes from kernel space into a user-space buffer, you get a pointer to the file's data and access it like a slice. The OS pages data in lazily from disk as you touch it which should be much more efficient.

We also switch to using PrescanMemmem as the default prescan method since it should also be much more efficient for relatively unique symbols (which is hopefully most searches), prescanning files by bytes instead of with a regex. I haven't noticed a big benefit in performance myself but also no worse performance.

@sirbrillig
sirbrillig force-pushed the add-memory-mapping-read branch from 787cba9 to 097b2d3 Compare March 15, 2026 22:44
@sirbrillig
sirbrillig merged commit f64d38e into trunk Mar 15, 2026
7 checks passed
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.

1 participant