nearcore icon indicating copy to clipboard operation
nearcore copied to clipboard

near_vm: reuse contract data/memory between contract executions

Open nagisa opened this issue 3 months ago • 0 comments

Currently we reuse memory maps that we allocate for storing compiled machine code for the contracts. This has been found to work great and improves the performance by a great degree. This is because the kernel needs to do quite a bit of accounting each time memory maps are set up.

Fortunately for us, the contracts all have a very specific amount of memory available to them. So we could allocate the necessary number of contract memories up-front and lock them so that they are not paged out (paging the memories back in => overhead)

The only thing we need to be careful about is that unlike code memories (which are not observable by the contracts), the data memories must be zeroed out after use in order to prevent leaking the data between contracts through them.

This could reduce the total execute_function_call time by roughly 20% on average in the post 1.39 world (provided that other relevant caches kick in.)

nagisa avatar Mar 21 '24 15:03 nagisa