#11883·substrate

Move the allocator inside of the runtime

Author: pepyakinCreated Jul 21, 2022Updated Aug 24, 2023

It is actually not a new idea and was considered very early. We ended up having the allocator provided by the host.

Lately, there were several discussions about moving the allocator back into the runtime.

  • One of those discussions anecdotally mentioned that there is a lot of overhead coming from the fact that the wasm-host boundary has to be crossed each time allocation and deallocation is performed. If we switched to allocator to the runtime, then each time host needs some memory it will have to ask the runtime to allocate a buffer. This should result in way fewer wasm-host boundary crossings though.
  • Another brought up the fact that it is not convenient from the perspective of long-term maintenance. Any implementation will have to follow the current implementation to the word.
  • This will remove the unsoundness discussed in the old issue https://github.com/paritytech/substrate/issues/300
  • Having the allocator adds flexibility as well. The runtime will be able to pick an allocator that suits the workflow it expects to have.
  • Technically, the allocator might ask for a different alignment. However, our allocator will always provide allocations aligned by 16 bytes.