Code Monkey home page Code Monkey logo

Comments (5)

evmar avatar evmar commented on July 3, 2024

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 MapFile.)

from n2.

evmar avatar evmar commented on July 3, 2024

I wrote a mini benchmark here.

On this Mac Air M2 for a random 1.4gb file:

without madvise:

  ./target/release/read-file mmap $F ran
    1.25 ± 0.01 times faster than ./target/release/read-file read $F

with madvise:

  ./target/release/read-file mmap $F ran
    1.36 ± 0.02 times faster than ./target/release/read-file read $F

So I conclude at least for this hw/OS that mmap is faster, and madvise helps too.

from n2.

Colecf avatar Colecf commented on July 3, 2024

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 MapFile.)

Sorry, this link should be permanent.

from n2.

Sarcasm avatar Sarcasm commented on July 3, 2024

Just a thought regarding "correctness" more than performances.

Is there any risk of the mmaped build.ninja changing during the build?
I had a bad experience trying to mmap user-controlled file, an update of the file at the wrong time could cause my process to crash with SIGBUS.
Edit: it could just be I didn't use the proper type of memory mapping.

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?

from n2.

evmar avatar evmar commented on July 3, 2024

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.

from n2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.