Small Data Optimization

Strings and vectors are so common in Rust code that they can hurt performance in various ways. This talk will cover strategies to improve performance when data is small enough to store on the stack or deduplicate.

Place
RustLab
Length
60 min
When
November 21st, 2023
09:30

Abstract

Outline:
- (1 min) Brief introduction of myself.
- (3 min) Discuss various crates for small string/vector optimizations.
 - Why they differ from one another.
 - Benefits: cache locality and less heap usage.
- (20 min) How to implement small data optimization:
 - (5 min) `enum` using no `unsafe`:
  - Demonstrates a core strength of Rust.
 - (12 min) Using `unsafe` to eke out as much performance as possible:
  - Benefits include: no wasted bytes and fine control over mutation strategies, like copy-on-write.
  - Need to be actively aware of all possible cases.
   - Niche optimization (e.g. `Option`) requires special care.
  - Test with MIRI: undefined behavior and endianness.
 - (3 min) Interning.
  - Deduplicating small strings.
  - Local versus global.
- (6 min) Conclusion:
 - "Small" changes meaning based on the context.
 - Rust can provide optimizations seen in C/C++ but it doesn't have to be difficult.
 - Don't need to reach for `unsafe` unless you are bringing something new to the table and have tested all possible cases.
- (10 min) Questions

Stay connected

You can subscribe to our newsletter to stay updated on the latest news and announcements. Follow us on social media to join our community and engage with other attendees, speakers, and staff. We're on Twitter, Mastodon, Youtube and Facebook. Don't forget to use our official hashtag #RustLab2023 to share your experience and connect with other attendees on social media.

Subscribe to our newsletter

We hate spam just as much as you do, which is why we promise to only send you relevant communications. We respect your privacy and will never share your information with third parties.
©2023 RustLab | The international conference on Rust in Florence-Design & devCantiere Creativo-Made withDatoCMS