-
Notifications
You must be signed in to change notification settings - Fork 275
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
Space efficient panic #4306
base: master
Are you sure you want to change the base?
Space efficient panic #4306
Conversation
67312c9
to
06c5ca8
Compare
The Firedancer team maintains a line-for-line reimplementation of the |
eb4f563
to
ab6c1ba
Compare
Adding new syscalls would require a SIMD. But maybe there is a way to keep using the existing syscalls but with a new panic handler? |
I'm not adding a new syscall. |
agave/programs/bpf_loader/src/syscalls/mod.rs Line 335 in 8a0c9b4
|
Problem
Our implementation of
custom_panic
can consume up to 25kb in contracts. This happens because it relies on theformat!
macro and, consequently, onstd::fmt::write
. They include many more functions in the contract and utilize dynamic dispatch, a technique that hinders compiler and link side optimizations for size reduction.Summary of Changes
I implemented a new
custom_panic
that functions independently with only two syscalls. It needs the stabilization offmt::Arguments::as_str
, which is happening in Rust 1.84 (see rust-lang/rust#132511).Size comparison
Take this simple contract as an example:
The binary size has whooping 18888 bytes (18kb).
The contract with an empty
custom_panic
function has 11536 bytes (11kb), so panic is consuming 7352 bytes.The contract with my new implementation has 11800 bytes (11kb), so my implementation has 264 bytes.
New error messages
The members of
fmt::Arguments
are all private, so I cannot build custom panic messages during runtime as Rust does (think about the error you get when you access an invalid index from a vector: we can only know the index and the vector length during execution time). These messages will be elided in the new panic implementation (see examples below). Error messages whose content is known at compile time will still be shown normally.The formatting is also different. It is more efficient to call
sol_log
multiple times than to format a string.Accessing an invalid index from a vector:
OLD:
NEW:
Calling unwrap on a None:
OLD:
NEW: