Faster conversion to String #196
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#196
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Hello, I had a need for much faster printing of UUIDs, and I created a library uuidtoa to prototype and use immediately in another project. I would like to send a PR to include the improved write speed here, but a couple of questions first.
fmt::Displayway of printing currently included in uuid?Thanks!
If we decide to go ahead with this... I would suggest waiting for about a month (currently working a whole set of breaking changes, and holding up on new features)
Thanks for building this @jwilm! I'm on board with pulling it in and improving our
Displayimplementation as well as offering an alternative lightweight way to write out UUIDs. Maybe we could add afmtmodule that includes thewrite_*methods?for the record me and @Dylan-DPC are onboard for this aswell...
@jwilm mind joining our gitter to discuss this?
@jwilm can start this for
Uuidtype?I still haven't managed to refactor the adapter types yet, so we can leave them for a later date
@jwilm any updates on this?
I won't personally have time to do this for a while, but you are welcome to pull in the code.
Uhmm no issues. We still have time for the next major release (0.7)
The format changes won't have breakage anyhow. The only API difference would be the addition of a
fmtmodule.At this point, we have frozen
0.6.xcycle sans bug fixes... It's just keep the load light on us... :)@huonw I think your PR fixes this right? we just don't have to have separate functions anymore for the similar speedups
It probably puts uuid similar to uuidtoa, but I suspect uuidtoa will still be slightly faster, and the uuid code still goes through the
fmtmachinery. Maybe @jwilm could compare the performance again.for reference: PR #303
available in
uuid@0.7.0-betaand onwardsI tried benchmarking it myself, using
github.com/huonw/uuid@e8504e4f5f.Results without LTO:
Results with LTO:
That is, in the full-optimisations case, there's ~30ns of overhead using
uuiddirectly (maybe 5ns of this is due to usingFormatter::write_strand thus callingstr::from_utf8instead ofstr::from_utf8_unchecked).One possibility for an API might be something like along the lines of https://doc.rust-lang.org/std/primitive.char.html#method.encode_utf8 e.g.
where the
vmust have length at least 36 (or 32, or 45, depending on the adapter). This can then be (somewhat) fluently used for writing to an intermediate buffer:And it can also be used naturally if the
strencoded value is all that's useful:This also avoids double buffering: unlike both
uuidanduuidtoa, this new form doesn't need to create its own[u8; N]buffer internally that it then copies into the real output.Variations/additions:
Uuid::encode_buffer() -> [u8; 45], so the latter case can befoo(uuid.to_hyphenated().encode_lower(&mut Uuid::encode_buffer()))without the programmer having think about the size of a printed UUIDencode_...onUuiditself, probably using the hyphenated form (this would probably best be in addition to the others, meaning the common case isuuid.encode_lower(&mut [0; 36]), but the simple and urn forms are still easily accessible).Thoughts?