-
Notifications
You must be signed in to change notification settings - Fork 71
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
Code size and dynamic dispatch #81
Comments
This also matters quite a bit for the primary use-case of borsh -- smart contracts compiled for WASM. And yeah, what you are saying makes sense -- there's indeed a tradeoff here between code-bloat and runtime performance (see serde vs deser (https://github.com/mitsuhiko/deser)). I don't think anyone fully explored these tradeoffs for borsh though. An obvious short-term win would be to fork borsh and publish a In an ideal world, this would be a feature of the main borsh crate, but I think exentining existing APIs to support that nicely wouldn't be easy, mostly because today's APIs don't seem to be in a particularly good shape: #51. |
Sounds like a smart way to go about this. Ideally at least for the common case with derived impls, it could be made to be an almost drop in replacement. I'll give this a go and see how it feels.
Yeah I was actually aiming for that initially, but quickly realized it would get pretty messy. |
Not sure this is the best place to have this conversation so feel free to close the issue!
I've been working on reducing (compiled) code size for an API that uses borsh heavily. This API includes a bunch of functions that use
BorshSerialize
generics. Between monomorphized copypasta, bad inlining and the error handling code for all theResult
s returned by all theBorshSerialize::serialize()
calls, these functions end up compiling down to a whole lot of code.When I first noticed the problem I thought oh well it's a shame, but I guess I'll just make these functions use dynamic dispatch. Except
BorshSerialize
isn't object safe, duh. So, armed with sed and a healthy dose of frustration, I hacked up aBorshDynSerialize
trait and derive that are exactly likeBorshSerialize
, but use dynamic dispatch for the writer so are object safe.Switching my project from
BorshSerialize
generics to dynamic dispatch withBorshDynSerialize
, cuts down.text
size of about 50k (of 390k total). Ugh.I realize this probably only matters for embedded and fringe programs that care about code size - but has this issue come up before? Has anyone thought about providing an API that is usable with dynamic dispatch?
The text was updated successfully, but these errors were encountered: