-
Notifications
You must be signed in to change notification settings - Fork 26
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
mmap input files rather than reading #109
Comments
Relevant code in Android's Ninja fork. (Not sure how to get a permalink to that commit but the file is unlikely to change much in the future, but it's the function |
I wrote a mini benchmark here. On this Mac Air M2 for a random 1.4gb file: without
with
So I conclude at least for this hw/OS that mmap is faster, and madvise helps too. |
Sorry, this link should be permanent. |
Just a thought regarding "correctness" more than performances. Is there any risk of the mmaped build.ninja changing during the build? The build.ninja file can be regenerated during build by the build system (I think cmake does this when a CMakeLists.txt changes), can this invalidate the memory mapping? |
The Linux man pages says it's undefined behavior. The Mac ones don't say either way. It is true that we wouldn't want to preserve the mapping beyond the point where the file might be rewritten though. |
[Consolidating some comments from #107 and #108]
Currently we read input files into a local buffer. I had thought this was better than mmap because:
However, it turns out that you can just mmap a private page at the end of the file to write the nul, and @Colecf says "Judging based on n2's tracing output, just reading the file into memory takes over twice as long as the android fork's entire ninja invocation".
The text was updated successfully, but these errors were encountered: