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: optimize error type #3596

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

Noah-Kennedy
Copy link
Contributor

@Noah-Kennedy Noah-Kennedy commented Mar 7, 2024

The allocations and frees for these errors can get expensive in some cases. Any reduction in allocator usage here helps some use cases a lot it seems.

@Noah-Kennedy Noah-Kennedy marked this pull request as draft March 7, 2024 17:14
@Noah-Kennedy
Copy link
Contributor Author

I'm leaving this as a draft while I look into ways to maybe make Cause faster as well.

@Noah-Kennedy
Copy link
Contributor Author

H2 is probably the most likely to cause perf issues for various reasons, so I'm focusing on that case for now.

@Noah-Kennedy Noah-Kennedy self-assigned this Mar 7, 2024
@Noah-Kennedy Noah-Kennedy added C-performance Category: performance. This is making existing behavior go faster. A-error Area: error handling labels Mar 7, 2024
@Noah-Kennedy Noah-Kennedy changed the title perf: don't box ErrorImpl perf: optimize error type Mar 7, 2024
@Noah-Kennedy Noah-Kennedy marked this pull request as ready for review March 7, 2024 18:48
@Noah-Kennedy
Copy link
Contributor Author

Marked as ready and squashing to make review easier. Gonna leave as two commits and squash again on merge.

We don't seem to need this boxed, and the allocs and frees do actually cost us a fair bit in prod according to my flamegraphs.
This seems to be costly as well for some applications, so let's avoid boxing unless we need to.
@tottoto
Copy link
Contributor

tottoto commented Mar 8, 2024

Looks good to me. However, as it increases a little complexity, I would think that there would needs to be a benchmark to show in which cases it is actually efficient or not, and how the efficiency is.

@seanmonstar
Copy link
Member

For context, the reason it was boxed before was:

  • To reduce return sizes of Result<T, Error>.
  • Because errors should be less common, it seemed better to make the error case more expensive if it allowed the good case to be any faster.

@Noah-Kennedy
Copy link
Contributor Author

Looks good to me. However, as it increases a little complexity, I would think that there would needs to be a benchmark to show in which cases it is actually efficient or not, and how the efficiency is.

I'll try and construct something, although I suspect that for most users this won't matter. That said, the effect of the double allocation is surprisingly significant.

@Noah-Kennedy Noah-Kennedy marked this pull request as draft March 8, 2024 20:19
@Noah-Kennedy
Copy link
Contributor Author

For context, the reason it was boxed before was:

* To reduce return sizes of `Result<T, Error>`.

* Because errors should be less common, it seemed better to make the error case more expensive if it allowed the good case to be any faster.

Hmm, the non-error case is a good point. I'll see if I can shrink this down.

I'm investigating more right now the actual production issue I saw with this, because there's a chance that this might not be a valid use of HTTP/2 semantics I'm looking at which is causing this. I might potentially close this if I decide that any case where this matters is an issue of "you're holding it wrong".

@seanmonstar
Copy link
Member

Did it turn out this isn't desired?

@seanmonstar seanmonstar added the S-waiting-on-author Status: waiting on the author to provide more info, or make changes. label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-error Area: error handling C-performance Category: performance. This is making existing behavior go faster. S-waiting-on-author Status: waiting on the author to provide more info, or make changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants