Solana Serialization Benchmarks

Blockiosaurus
Metaplex
Published in
3 min readAug 7, 2024

--

Every few weeks I’ll go a little hard on the whiskey and try to rewrite some of our protocols without Borsh (yeah, I’m fun at parties). Last week involved some nice scotch and writing a new resource for Solana developers.

Borsh, for those who don’t know, is the Serialization-Deserialization (SerDes) framework that most of Solana is built on. It’s the default in Anchor, in Umi, and parts of the SVM use it as well. Unlike the EVM, the SVM isn’t opinionated about the SerDes protocol, and will let you use pretty much any type of framework you want.

Borsh is far from the only option; there are many libraries for various use cases and in different states of completeness.

😱

Those of you who I haven’t bored to death already probably know this, and may even be familiar with the Rust Serialization Benchmark repository. For those who aren’t, this page provides a pretty good comparison of the most popular SerDes frameworks and runs a comprehensive set of benchmarks on different data types, listing execution times and rankings to show where different frameworks perform best.

This is the page I turn to on my frequent side quests to find the best SerDes library for Solana programs. I’ll pick something off of the list and attempt to use it in a baseline Solana program.

But it’s always painful. Every library is different, has different strengths and weaknesses, and often vastly different semantics on how the library should be used. I’ve lost hours on finicky rkyv code, trying to wrangle the unsafe mutations.

The Rust Serialization Benchmark repo is amazing, and extremely helpful for its targeted use case of serializing objects into network packets. But what works for networking, doesn’t necessarily work for Solana. Those who’ve read my previous article know that Solana programming requires a careful balance between compute, memory, and the rent required to store data. And we need a resource that keeps that balance in mind.

Introducing the Solana Serialization Benchmark, a repository inspired by its predecessor, but specifically targeting Solana developers and the unique constraints needed by SVM programs.

The goal of this repository is to provide head-to-head comparisons of the of different serialization frameworks, executed in the SVM environment and measured in terms of Compute Units and Account Space. A side benefit of these benchmarks is the inclusion of example code for each framework, letting developers hit the ground running if they wish to venture beyond the confines of Borsh.

Plus a little something for the other graph nerds

Future improvements include, a feature matrix showing what each framework does and doesn’t support and brief summaries on where different frameworks excel.

For those interested in contributing, the CONTRIBUTING.md file provides a comprehensive explanation of what needs to be added to include a new framework, and how to run the benchmarks. And as always, I’m open to any feedback or suggestions on how to make this tool better!

--

--