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

perf: mark dna::complement as inline #510

Merged
merged 4 commits into from Jan 2, 2023
Merged

perf: mark dna::complement as inline #510

merged 4 commits into from Jan 2, 2023

Conversation

kloetzl
Copy link
Contributor

@kloetzl kloetzl commented Dec 22, 2022

This speeds up computing the complement on a long string by ~2.3x. Not sure why rust doesn't inline such a trivial function on its own.

I didn't manage to compile your benchmarks, hence I can only point to the results from my own project.

dna4_revcomp time: [688.18 µs 690.09 µs 692.27 µs]
dnax_revcomp time: [3.0615 ms 3.0705 ms 3.0815 ms]

rust-bio time: [12.029 ms 12.105 ms 12.212 ms]
rust-bio inlined time: [5.0742 ms 5.0901 ms 5.1087 ms]

There is still a small overhead of Rust over C. I think Rust repeatedly checks that a as usize is a valid index in COMPLEMENT. While that is usually not a problem, it is here, because the loop is so small and the extra instructions clog the pipeline.

This speeds up computing the complement on a long string by ~2.3x.
@kloetzl kloetzl changed the title mark dna::complement as inline perf: mark dna::complement as inline Dec 22, 2022
@coveralls
Copy link

coveralls commented Dec 22, 2022

Coverage Status

Coverage: 80.38% (+0.0%) from 80.38% when pulling f43f02b on kloetzl:patch-1 into e7f5744 on rust-bio:master.

Copy link
Contributor

@dcroote dcroote left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, this makes sense. Can you also do the same for the complement function in src/alphabet/rna.rs?

I didn't manage to compile your benchmarks

Benchmarks require using nightly - did you try that? It'd be nice to add an alphabets.rs file to the benchmarks directory for testing some of these string functions like complement and revcomp.

@kloetzl
Copy link
Contributor Author

kloetzl commented Dec 24, 2022

Can you also do the same for the complement function in src/alphabet/rna.rs?

Sure, will do.

Benchmarks require using nightly - did you try that?

Didn't know that. Will give it a go.

@dcroote
Copy link
Contributor

dcroote commented Dec 31, 2022

Thanks but it looks like you added #[inline] to revcomp instead of complement in rna.rs

@kloetzl
Copy link
Contributor Author

kloetzl commented Jan 2, 2023

Thanks but it looks like you added #[inline] to revcomp instead of complement in rna.rs

Thanks for the thorough review. I blame my lingering cold.

Copy link
Contributor

@dcroote dcroote left a comment

Choose a reason for hiding this comment

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

Thanks!

@dcroote dcroote merged commit bd08234 into rust-bio:master Jan 2, 2023
@kloetzl kloetzl deleted the patch-1 branch January 3, 2023 10:09
@kloetzl
Copy link
Contributor Author

kloetzl commented Jan 3, 2023

Thanks for merging!

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

3 participants