nearcore icon indicating copy to clipboard operation
nearcore copied to clipboard

mmap for filesystem compiled contract cache

Open nagisa opened this issue 3 months ago • 0 comments

The Compiled Contract Cache introduced in https://github.com/near/nearcore/pull/10791 is reading files off disk using the plain old read(2) call. Although the profile looks much better than with the RocksDB-based cache, the read(2) is very prominent in the profile.

For the most part, these files should be pretty warm in the page cache, and we don't actually need the ownership of these bytes in order to load the contract. Thus using a mmap to put a view of this file into the memory space our our process might end up quite a bit faster than what we are currently doing (which is at least one big copy of the file contents, possibly from the file cache where the file already might be present at.)

mmap also fits the bill pretty well because we will usually need the whole thing and won't be doing "random" accesses to small parts of the executable.

nagisa avatar Mar 15 '24 14:03 nagisa