def get(self):
self.ready.wait()
- if isinstance(self.content, mmap.mmap):
+ # 'content' can None, an empty byte string, or a nonempty mmap
+ # region. If it is an mmap region, we want to advise the
+ # kernel we're going to use it. This nudges the kernel to
+ # re-read most or all of the block if necessary (instead of
+ # just a few pages at a time), reducing the number of page
+ # faults and improving performance by 4x compared to not
+ # calling madvise.
+ if self.content:
self.content.madvise(mmap.MADV_WILLNEED)
return self.content
os.remove(tmpfile)
except:
pass
- return False
def size(self):
if self.content is None: