Skip to content

Use mmap in ReadAll if possible #2122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

tgulacsi
Copy link
Contributor

PR Details

Use mmap instead of io.ReadAll, if possible

Description

Introduce readAll function which uses mmap if possible, io.ReadAll otherwise.

Related Issue

#2121

Motivation and Context

Memory inefficiency.

How Has This Been Tested

go test

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@xuri xuri added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 27, 2025
@xuri xuri linked an issue Apr 27, 2025 that may be closed by this pull request
2 tasks
@shcabin
Copy link
Contributor

shcabin commented Apr 29, 2025

Have you compared it with io.Copy? It seems that io.Copy is more compatible and not fallback to io.ReadAll().

In my work environment there is only Fd() uintptr (not found Fd() int), and I am not sure why, so I am unable to conduct effective testing mmap.

@tgulacsi
Copy link
Contributor Author

My bad, you're right, Fd() returns uintptr.

This mmap is not for speed, it's for decreasing RSS by using the kernel-supplied probably-in-filecache []byte of the file.

os.File.Fd() never returned int...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use mmap if possible (can save memory with big files)
3 participants