Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid eager loading of wasm binaries when executing a function call #10801

Closed
bowenwang1996 opened this issue Mar 14, 2024 · 2 comments · Fixed by #10852
Closed

Avoid eager loading of wasm binaries when executing a function call #10801

bowenwang1996 opened this issue Mar 14, 2024 · 2 comments · Fixed by #10852
Assignees
Labels
A-storage Area: storage and databases A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) T-contract-runtime Team: issues relevant to the contract runtime team

Comments

@bowenwang1996
Copy link
Collaborator

In execute_function_call, we always first load the wasm binary

let code = match get_contract_code(&runtime_ext, account, apply_state.current_protocol_version)
. However, this step is only needed if the contract has not been compiled. We should refactor to avoid unnecessarily loading of wasm binaries.

@nagisa
Copy link
Collaborator

nagisa commented Mar 15, 2024

This can be pretty difficult to achieve however. The ContractCode that we're loading here besides the wasm code itself also contains a CryptoHash which is the key into the compiled contract cache.

The obvious thing to do would be to split them up into independent columns perhaps? Or independent key-values within this column? RocksDB does return memory slices that we don't need to copy necessarily, but I believe that the data still needs to be read from the disk and decompressed in full before this slice gets passed to the caller.

@nagisa nagisa added A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) T-contract-runtime Team: issues relevant to the contract runtime team A-storage Area: storage and databases labels Mar 15, 2024
@bowenwang1996
Copy link
Collaborator Author

@nagisa contract hash is stored as part of Account, which is readily available in execute_function_call

github-merge-queue bot pushed a commit that referenced this issue Mar 22, 2024
…hed (#10852)

I’m not super happy with how `with_compiled_and_loaded` ended up being
very specialized to this use case, but OTOH there’s not really much
point in keeping it separated from `run` considering it’s being called
at exactly one place.

I guess we should add this to the pile of tech debt to deal with after
1.39, though it probably doesn’t deserve a project as it should be easy
enough.

Closes #10801
Cc #10775 and
near/near-one-project-tracking#59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-storage Area: storage and databases A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) T-contract-runtime Team: issues relevant to the contract runtime team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants