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

Optimize nth and nth_back for BoundTupleIterator #4897

Merged

Conversation

Owen-CH-Leung
Copy link
Contributor

See #4787

This PR optimizes nth and nth_back for BoundTupleIterator, and added unittest & benchmarks for these 2 APIs. Here are the benchmark of the optimized nth and nth_back:

On Stable toolchain

With Optimization

tuple_nth               time:   [283.96 ns 286.42 ns 291.01 ns]
tuple_nth_back          time:   [288.92 ns 289.83 ns 291.15 ns]

The default nth and nth_back implementation

tuple_nth               time:   [2.0933 µs 2.0961 µs 2.0992 µs]
tuple_nth_back          time:   [2.0425 µs 2.0445 µs 2.0468 µs]

On nightly toolchain

With Optimization

tuple_nth               time:   [275.54 ns 275.97 ns 276.49 ns]
tuple_nth_back          time:   [315.25 ns 343.92 ns 375.81 ns]

The default nth and nth_back implementation

tuple_nth               time:   [1.9814 µs 1.9846 µs 1.9883 µs]
tuple_nth_back          time:   [2.0314 µs 2.0705 µs 2.1266 µs]

@Owen-CH-Leung Owen-CH-Leung marked this pull request as ready for review February 9, 2025 15:38
Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Thank you very much, just some small comments.

Copy link

codspeed-hq bot commented Feb 13, 2025

CodSpeed Performance Report

Merging #4897 will degrade performances by 12.82%

Comparing Owen-CH-Leung:optimize_nth_and_nthback_for_boundtupleiter (7ac2f20) with main (2c732a7)

🎉 Hooray! codspeed-rust just leveled up to 2.7.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

❌ 1 regressions
✅ 85 untouched benchmarks
🆕 2 new benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
extract_float_downcast_fail 396.7 ns 455 ns -12.82%
🆕 tuple_nth N/A 4.3 µs N/A
🆕 tuple_nth_back N/A 4.3 µs N/A

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks 🚀

@Icxolu Icxolu added this pull request to the merge queue Feb 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2025
@Icxolu Icxolu added this pull request to the merge queue Feb 13, 2025
Merged via the queue into PyO3:main with commit 6028cfc Feb 13, 2025
46 of 48 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.

2 participants