smithy-rs icon indicating copy to clipboard operation
smithy-rs copied to clipboard

More efficient mime type parsing in server SDKs; avoid `mime` crate

Open david-perez opened this issue 1 year ago • 2 comments

We're currently creating one OnceCell per operation backing a static mime::Mime type for the operation's expected (if present) client Accept header value, only to then decompose it into type + subtype and perform a case-insensitive string comparison check against the actual incoming Accept header value.

It would be more efficient to directly compare &strs and avoid incurring the atomic read.

A simpler, more efficient, and type-safe approach would be to directly switch to something like mediatype, which is const-constructible and zero-copy. Note that mime is not actively maintained.

See https://github.com/awslabs/smithy-rs/pull/2607#discussion_r1173687692 and https://github.com/awslabs/smithy-rs/pull/2629, the PR where we started using OnceCells for this.

david-perez avatar May 03 '23 11:05 david-perez