This is the story of how we made the conduit-mime-types Rust crate almost infinitely faster, using perfect hash functions and compile-time code genera

Blog: rust-phf: the perfect hash function

submited by
Style Pass
2022-06-24 02:30:13

This is the story of how we made the conduit-mime-types Rust crate almost infinitely faster, using perfect hash functions and compile-time code generation.

Let's start at the beginning. crates.io is the package registry of the Rust programming language, or in simpler terms: the place where you can download all the dependencies of your apps. The crates.io server itself is also built with Rust, and specifically with an HTTP framework called conduit.

conduit has a component called conduit-static, which is responsible for efficiently serving static files to the users. conduit-static is itself relying on a package called conduit-mime-types, which is the main focus of this story. The purpose of this package is to map filename extensions to MIME types and vice-versa.

In other words: if you call get_mime_type("xls") the function should return Some("application/vnd.ms-excel") and if you call get_extension("application/vnd.ms-excel") it should return Some("xls").

Leave a Comment
Related Posts