adiroy28852 commented on issue #55656:
URL: https://github.com/apache/arrow/issues/55656#issuecomment-7108190809

   Hi @behroozazarkhalili
   
   I would like to work on this. I read through this, and the issue that 
mentions this (#18920). I am thinking we could follow the approach suggested 
there: a per-file flag on the memory map, with the current behaviour kept as 
the default.
   
   The idea is:
   
   **C++**
   - Add `MemoryMappedFile::set_auto_will_need(bool)` and `bool 
auto_will_need() const`, defaulting to `true`.
   - In `MemoryMappedFile::ReadAt`, call `MemoryAdviseWillNeed` only when the 
flag is set. `Read()` goes through `ReadAt`, so it would be covered too.
   - Store the flag as an `std::atomic<bool>` on the shared `MemoryMap`, since 
`ReadAt` is documented as thread-safe.
   - Explicit `WillNeed()` calls would not be affected, and the `Open`/`Create` 
signatures would stay the same, so the change is purely additive.
   
   **Python**
   - Add a keyword-only argument: `pa.memory_map(path, mode='r', *, 
auto_will_need=True)`.
   - Add a `MemoryMappedFile.auto_will_need` property (getter and setter).
   
   Then `datasets`, or any caller that wants lazy zero-copy access, could do:
   
       with pa.memory_map(path, auto_will_need=False) as source:
           table = pa.ipc.open_stream(source).read_all()
   
   Two other options I considered:
   1. **An option on `IpcReadOptions`.** This is more targeted, but the advice 
comes from the IO layer, so the flag would have to be passed down to the file 
anyway. It also wouldn't help non-IPC users of memory maps.
   2. **Turning the advice off by default.** This is simpler, but it changes 
behaviour for people who currently benefit from the prefetch, so keeping it 
opt-in seems safer.
   
   I'll start working on an MR if they sound good. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to