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

Const guid #279

Merged
merged 11 commits into from Aug 3, 2020
Merged

Const guid #279

merged 11 commits into from Aug 3, 2020

Conversation

rylev
Copy link
Contributor

@rylev rylev commented Jul 21, 2020

Fixes #136

Note that this will push the MSRV to Rust 1.46 which is currently in beta.

@rylev rylev closed this Jul 21, 2020
@rylev rylev reopened this Jul 21, 2020
src/guid.rs Outdated Show resolved Hide resolved
@rylev
Copy link
Contributor Author

rylev commented Jul 22, 2020

@kennykerr this is ready for review. It won't pass CI until I update const-sha1 with the changes necessary to get this to work, but I'd like to have your eyes on this before I push a new version. Once that's done, I'll push a new version of const-sha1 and we can merge this.

One thing we'll need to consider is that this will cause the crate to only work on beta. If we want we can wait until the next release of Rust before merging this.

Cargo.toml Outdated Show resolved Hide resolved
kennykerr
kennykerr previously approved these changes Jul 22, 2020
Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

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

Thanks!

@kennykerr
Copy link
Collaborator

Can't wait to do some run time comparative performance testing with this change.

kennykerr
kennykerr previously approved these changes Jul 31, 2020
@rylev rylev merged commit f9911ae into master Aug 3, 2020
@rylev rylev deleted the const-guid branch August 3, 2020 14:49
@Boddlnagg
Copy link

Boddlnagg commented Aug 3, 2020

Note that this is a breaking change for consumers of winrt-rs who have their own impls of winrt::ComInterface. This should be reflected in the next release version.

(It might also be a breaking change because of the MSRV.)

@rylev
Copy link
Contributor Author

rylev commented Aug 3, 2020

Yes, our next version will be 0.8 for multiple reasons 👍 .

@kennykerr
Copy link
Collaborator

Here's the performance impact of const guids. Consider the following sample:

fn main() -> Result<()> {
    let uri = Uri::create_uri("http://kennykerr.ca")?;
    let query = uri.query_parsed()?;

    let start = std::time::Instant::now();

    for _ in 0..1_000_000 {
        let s = query.size()?;
        debug_assert!(s == 0);
    }

    println!("{:5}ms", start.elapsed().as_millis());
    Ok(())
}

The size method is on a required but non-default interface of the WwwFormUrlDecoder class returned by the query_parsed method. That means that every time size is called, QueryInterface must first be called to retrieve the appropriate vtable. This is just one of those details that a language projection hides from the language as a convenience, but such hidden costs need to be as minimal as possible.

Before this commit:

C:\git\rust\scratch>cargo run --release
    Finished release [optimized] target(s) in 0.09s
     Running `target\release\scratch.exe`
  829ms

After this commit:

C:\git\rust\scratch>cargo run --release
    Finished release [optimized] target(s) in 0.09s
     Running `target\release\scratch.exe`
   21ms

That's about 40 times faster and on par with C++/WinRT.

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.

Calculate generic GUIDs at compile time
3 participants