Skip to content

Special case bool literals #784

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

Merged
merged 2 commits into from
Jul 17, 2023
Merged

Special case bool literals #784

merged 2 commits into from
Jul 17, 2023

Conversation

adriangb
Copy link
Member

I did this while working on #783 but it's not needed there. Posting it here in case we think it's worth it. @davidhewitt can you take a look and close if you think it's not worth it or too far from what you'd implement?

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 17, 2023

CodSpeed Performance Report

Merging #784 will improve performances by 10.38%

Comparing bool-literal (a36404e) with main (ff660dc)

Summary

🔥 1 improvements
✅ 125 untouched benchmarks

Benchmarks breakdown

Benchmark main bool-literal Change
🔥 test_small_class_core_model 51.1 µs 46.3 µs +10.38%

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Do I read from the benchmark that this makes things slower?

Comment on lines +51 to +57
if let Ok(bool) = k.strict_bool() {
if bool {
expected_bool.true_id = Some(id);
} else {
expected_bool.false_id = Some(id);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The chain of if let Ok(...) = input.x() here just seems to scream at me for the input-as-enum we spoke about the other day...

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed!

@adriangb
Copy link
Member Author

I guess so. I don't trust our benchmarks because of all of the noise going on, but this is the one I would expect to get slower, so maybe it's real. Nonetheless, I'm surprised it's slower at all. That benchmark should just consist of checking a None variant, no cloning, calling into Python, etc.

@adriangb
Copy link
Member Author

Case in point: another benchmark shows a larger improvement than the literal benchmark shows a regression, which is indicates to me there’s a lot of noise

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Overall I see no harm in adding this and I think if the benchmark regression is real, it's small and we can win it back in future with input-as-enum or other optimizations.

@adriangb adriangb merged commit 1382deb into main Jul 17, 2023
@adriangb adriangb deleted the bool-literal branch July 17, 2023 18:02
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