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

speed up marshaling of transport parameters #3531

Merged
merged 1 commit into from
Aug 29, 2022

Conversation

marten-seemann
Copy link
Member

This is not in the critical path, so technically this is not a part of #3526. It's fun to see how much we can gain anyway, and such an easy and self-contained change that it's definitely worth doing.

The speedup comes from multiple sources:

  1. We now preallocate a byte slice, instead of appending multiple times.
  2. Marshaling into a byte slice is faster than using a bytes.Buffer.
  3. quicvarint.Write allocates, while quicvarint.Append doesn't.
benchmark                                  old ns/op     new ns/op     delta
BenchmarkTransportParametersMarshal-10     368           196           -46.80%

benchmark                                  old allocs     new allocs     delta
BenchmarkTransportParametersMarshal-10     14             1              -92.86%

benchmark                                  old bytes     new bytes     delta
BenchmarkTransportParametersMarshal-10     273           256           -6.23%

The speedup comes from multiple sources:
1. We now preallocate a byte slice, instead of appending multiple times.
2. Marshaling into a byte slice is faster than using a bytes.Buffer.
3. quicvarint.Write allocates, while quicvarint.Append doesn't.
@marten-seemann marten-seemann force-pushed the speed-up-transport-parameter-marshaling branch from 3db3c6c to 9ae9a90 Compare August 29, 2022 09:57
@codecov
Copy link

codecov bot commented Aug 29, 2022

Codecov Report

Base: 85.56% // Head: 85.55% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (9ae9a90) compared to base (3f1adfd).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3531      +/-   ##
==========================================
- Coverage   85.56%   85.55%   -0.00%     
==========================================
  Files         137      137              
  Lines       10087    10086       -1     
==========================================
- Hits         8630     8629       -1     
  Misses       1080     1080              
  Partials      377      377              
Impacted Files Coverage Δ
internal/handshake/crypto_setup.go 66.74% <100.00%> (-0.08%) ⬇️
internal/handshake/session_ticket.go 100.00% <100.00%> (ø)
internal/wire/transport_parameters.go 89.21% <100.00%> (+0.04%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@marten-seemann marten-seemann merged commit 7023b52 into master Aug 29, 2022
@marten-seemann marten-seemann deleted the speed-up-transport-parameter-marshaling branch August 30, 2022 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants