Rust APIs for performance & type safety
a case study
1. Why do rustaceans care? 🦀
3. Some ideas for fix-toy
4. Looking back 🤔
Doing some archeology
What is FIX?
Financial Information eXchange protocol
- A domain-specific data transfer protocol.
- Popularized in the '90s.
- Text-based, human-readable. Mostly.
Format: tag=value pairs, separated by SOH character.
TW: FIX is atrocious.
What we want out of fix-toy
A crate for FIX newcomers as well as demanding users.
1. Not standard-compliant:
2. No streaming support!
3. DevX considerations.
4. N+1 allocations.
5. No choice of
Introducing the FIX dictionary
A XML specification for FIX messages
- Flexible querying
- Easily clonable
...and the ugly
- Expensive initialization
- Queries are expensive
- Huge memory consumption
Adding a dependency to the dictionary
- Parsing requires taking a
- DevX suggests
Woeful restrictions for downstream users. 🐌
FIX doesn't integrate any framing mechanism. 🖼️
Tokio to the rescue! 🚀
datagrams vs streams?
So, we're making the api more complete
We can solve these problems with traits: the most comprehensive type abstraction tool we have in Rust.
Much more we could do 👩🏼🔬
Huge dependencies like
Dictionary are fertile grounds for trait-based abstractions.
RFC 1598 - GATs
RFC 3185 - async fn in traits
RFC 2532 - default associated types
Traits enable late binding implementation details
We often introduce traits out of necessity, reacting to emerging requirements.
What if we were more proactive about this? ⚡
Does this type let me do that?
What is it exactly that I need here?
Public crate design differs greatly from private codebases.
- Traits allow us to be more agnostic towards downstream users' situations and use cases.
- This is only possible because of the added structure.
Don't be scared to populate your crates with many traits.
Your SemVer will be alright. Really.
Food for thought
Dictionaryaway lets us explore truly zero-cost codegen solutions. 🏃🏻♂️
- Placing field getters into a trait would allow code reuse for JSON, Protobuf, and other FIX formats.
- Surrogate traits with associated would help to keep APIs slim and simple by introducing hierarchies.
Rust APIs for performance & type safety: a case study