Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve try_parse and encode performance #562

Merged
merged 2 commits into from Nov 14, 2021
Merged

Conversation

Nugine
Copy link
Contributor

@Nugine Nugine commented Nov 14, 2021

I'm submitting a refactor

Description

This PR improves the performance of Uuid::{try_parse, parse_str} and {Simple, Hyphenated, Braced, Urn}::{encode_lower, encode_upper}

bench before after
encode_hyphen 25 ns 15 ns
encode_simple 23 ns 15 ns
encode_urn 29 ns 16 ns
hyphenated 43 ns 37 ns
simple 39 ns 32 ns
urn 46 ns 37 ns
parse_invalid_character 72 ns 63 ns
parse_invalid_group_len 81 ns 73 ns
parse_invalid_groups 94 ns 90 ns
parse_invalid_len 88 ns 86 ns
parse_nil 46 ns 26 ns
parse_nil_hyphenated 47 ns 28 ns
parse_random 46 ns 26 ns
parse_random_hyphenated 47 ns 28 ns
parse_urn 49 ns 29 ns

Related issues

#551
#561

) -> &'b mut str {
const LEN: usize = 32;
let buf = &mut buffer[..LEN];
unsafe {
Copy link
Member

@KodrAus KodrAus Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could move the SAFETY comment to outside of the unsafe block here to also cover the ptr::write call?

The as_mut_ptr call isn't unsafe so we could also pull that one out.

Copy link
Member

@KodrAus KodrAus left a comment

Thanks for working on this @Nugine! I just had one nit-picky comment around SAFETY comments on the unsafe blocks.

It would be great to come back through and add some docs describing how we parse the various shaped UUIDs. At the moment I think a casual passer-by might have a hard time following along. I'm happy to come back and do that later though unless you'd like to write it up.

) -> &'b mut str {
const LEN: usize = 32;
let buf = &mut buffer[..LEN];
unsafe {
Copy link
Member

@KodrAus KodrAus Nov 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could move the SAFETY comment to outside of the unsafe block here to also cover the ptr::write call?

The as_mut_ptr call isn't unsafe so we could also pull that one out.

@KodrAus KodrAus merged commit 3a6aeb1 into uuid-rs:main Nov 14, 2021
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants