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

Reduce compiled program sizes by reducing serialization bloat #23075

Closed
alessandrod opened this issue Feb 11, 2022 · 0 comments
Closed

Reduce compiled program sizes by reducing serialization bloat #23075

alessandrod opened this issue Feb 11, 2022 · 0 comments
Labels
stale [bot only] Added to stale content; results in auto-close after a week.

Comments

@alessandrod
Copy link
Contributor

Problem

Borsh and bincode, the serialization libraries used by the solana-program crate and many solana programs, bloat significantly the .text section of compiled SBF programs. Bincode is especially bad since it pulls in serde, which notoriously generates a lot of code.

Proposed Solution

Ideally we should put APIs that use borsh and serde behind rust features, so that consumers of the solana-program crate would have a way to opt out of either (or both).

Doing this for bincode (and therefore serde) might be nearly impossible tho considering how pervasively it is used everywhere (eg sysvars and system instructions). Until we switch the core stuff away from bincode, a more realistic short term approach could be building something like https://docs.rs/miniserde/latest/miniserde for bincode.

As for borsh, I've fixed an issue in near/borsh-rs#77 and have been looking at another possible workaround, see near/borsh-rs#81. My hacked up version of BorshDynSerialize reduces the size of solana-program-library significantly. We could try switching to dynamic dispatch in solana-program and anchor too (anchor uses borsh by default and seems to generate a lot of boilerplate).

Part of the reason why these libraries generate a lot of code is that they make heavy use of generics and interact badly with the rust monomorphizer. We could try enabling rust-lang/rust#48779 by default for SBF to try and reduce monomorphized duplicates. I have in fact tried this, and it makes a big impact for SPL, but it also causes regressions for other programs I've tried, so there's $some work to do there.

@github-actions github-actions bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Feb 13, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale [bot only] Added to stale content; results in auto-close after a week.
Projects
None yet
Development

No branches or pull requests

1 participant