Add encode_{lower,upper} to formatting adapters for core::fmt-less rendering. #311
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!311
Loading…
Reference in a new issue
No description provided.
Delete branch "encode"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm submitting a(n) feature
Description
Add encode_{lower,upper} to formatting adapters for core::fmt-less rendering.
Motivation
These are noticably faster (20ns, ~50%) as they avoid all the virtual
call overhead of core::fmt/write! (etc.). This also improves the
performance of (human-readable) serde encoding, since that previously
went through core::fmt.
Tests
Benchmark results both with LTO and without including a comparison
against crates.io/crates/uuidtoa:
This is now essentially as fast as uuidtoa at its fastest (and
significantly faster than it, without LTO), and the remaining
difference is likely the use of the checked
str::from_utf8_mut.Benchcmp for the existing benchmarks using the existing APIs (only the
ones that changed):
That is, JSON encoding takes 40% less time, and even core::fmt
formatting for the formats that use hyphens got slightly faster too.
Related Issue(s)
Closes #196.
Self doesn't work https://github.com/rust-lang/rust/issues/52808
github.com/uuid-rs/uuid@cf6703d599/src/adapter/core_support/mod.rs (L28-L33)This comment was generated by todo based on a
TODOcomment in cf6703d5998d602d85c532f6d378625cd5275956 in #311. cc @huonw.Self doesn't work https://github.com/rust-lang/rust/issues/52808
github.com/uuid-rs/uuid@dcdbe7b19e/src/adapter/core_support/mod.rs (L28-L33)This comment was generated by todo based on a
TODOcomment in dcdbe7b19e4dd0e38fbb7f08b319a5db412531dc in #311. cc @huonw.Thanks @huonw!
The additional docs, tests and benches are great. I've just left a few little nitpicks.
@ -187,6 +188,67 @@ impl Uuid {}It might be nicer to use
expectwith a message here indicating that this shouldn't happen rather thanunwrap.Is there a reason to pass a start index in rather than expect
full_bufferto have been sliced?@ -187,6 +188,67 @@ impl Uuid {}Yeah, for the URN case: there's a prefix that gets added in front of what
encodedoes, but I want to have that prefix included in the return value, and thus also in thefrom_utf8_mutcall in this function.@ -187,6 +188,67 @@ impl Uuid {}Ah gotcha 👍
@ -20,3 +20,3 @@) -> Result<S::Ok, S::Error> {if serializer.is_human_readable() {serializer.collect_str(&self.to_hyphenated())serializerjust a question: was
collect_strthe wrong function to use? curious..@ -20,3 +20,3 @@) -> Result<S::Ok, S::Error> {if serializer.is_human_readable() {serializer.collect_str(&self.to_hyphenated())serializerI don't think so, it's much more direct and less error prone than manually using the
Displayimpls to construct astr. This new APIs is only a little bit more complicated to use withserialize_strthancollect_str, so I think it makes sense to switch.Self doesn't work https://github.com/rust-lang/rust/issues/52808
github.com/uuid-rs/uuid@4eee4f18ce/src/adapter/core_support/mod.rs (L28-L33)This comment was generated by todo based on a
TODOcomment in 4eee4f18ce57d902c8882e0eb47b1494552d1d38 in #311. cc @huonw.Self doesn't work https://github.com/rust-lang/rust/issues/52808
github.com/uuid-rs/uuid@246c7f7586/src/adapter/core_support/mod.rs (L28-L33)This comment was generated by todo based on a
TODOcomment in246c7f7586in #311. cc @huonw.@ -187,6 +188,67 @@ impl Uuid {}Done.
@ -187,6 +188,67 @@ impl Uuid {}I added a doc comment to
encodethat explains this.This looks good to me! Thanks @huonw
bors r+
@KodrAus we are waiting until
0.7.0release before merging thisSelf doesn't work https://github.com/rust-lang/rust/issues/52808
github.com/uuid-rs/uuid@469acc7634/src/adapter/core_support/mod.rs (L28-L33)This comment was generated by todo based on a
TODOcomment in469acc7634in #311. cc @huonw.bors: r+
Build succeeded