solana-labs / solana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://solanalabs.com
Apache License 2.0
13.17k stars 4.29k forks source link

Program serialization is inefficient due to copies of accounts into and out of the program #14691

Open jackcmay opened 3 years ago

jackcmay commented 3 years ago

Problem

BPF program parameters (accounts, instruction data, etc...) are copy-serialized into an input buffer on program entry and back out on program exit. The overhead of copying has become significant as use cases require larger and larger accounts.

For context: https://github.com/solana-labs/solana/issues/14523

Proposed Solution

jackcmay commented 3 years ago

@Lichtso The current infrastructure allows a program to create a new account with a data size up to 10k via the SystemProgram::CreateAccount instruction. This is essentially seen as a realloc of the new account's data size. When loading all the accounts into a consecutive memory range, what did you have in mind for account allocation? We will want to put in place a mechanism that allows for both the currently allowed alloc up to 10k but also for future general re-allocations which will include both increasing and decreasing the account size up to the max account size (1GB iirc).

Lichtso commented 3 years ago

@jackcmay Good question. Do we know the number and size of SystemProgram::CreateAccount before the transaction is processed? If we at least know the maximum number of accounts created, then we can leave that amount of padding in the consecutive memory range for creations and reallocations. For future bigger reallocations it might actually make sense to reserve continuous memory address space using mmap.

jackcmay commented 3 years ago

Another good question, the current transaction format does not specify inner-instructions so we can't know all of the SystemProgram instructions that might be called by a particular transaction.

Lichtso commented 2 years ago

I think we are close to finally fixing this issue with: https://github.com/solana-labs/solana/pull/28053