Skip to content

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Nov 4, 2023

Messing around with heaptrack in #1563, I identified a couple of places with relatively high allocation counts when running simpleclient (modified to do several connections in a row).

In CertificatePayloadTls13::convert, we were unnecessarily doing a clone. Fixed this by converting that function to take self, and the two callsites to use require_handshake_msg_move! instead of require_handshake_msg!.

In ChunkVecBuffer::consume, when a chunk is partially consumed, we were calling Vec::split_off, which always "Returns a newly allocated vector." Instead, use Vec::drain, which reuses the current allocation.

In local testing, the change to ChunkVecBuffer::consume appeared to reduce allocations by almost 10%. I'll be curious to see if the CI run shows actual runtime performance.

Copy link

codecov bot commented Nov 4, 2023

Codecov Report

Merging #1571 (c4d279b) into main (793ca28) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1571      +/-   ##
==========================================
- Coverage   96.41%   96.41%   -0.01%     
==========================================
  Files          75       75              
  Lines       15524    15517       -7     
==========================================
- Hits        14968    14961       -7     
  Misses        556      556              
Files Coverage Δ
rustls/src/check.rs 88.88% <ø> (ø)
rustls/src/client/tls13.rs 97.03% <100.00%> (-0.02%) ⬇️
rustls/src/msgs/handshake.rs 98.10% <100.00%> (-0.01%) ⬇️
rustls/src/server/tls13.rs 96.96% <100.00%> (-0.01%) ⬇️
rustls/src/vecbuf.rs 98.88% <100.00%> (ø)

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@jsha jsha force-pushed the fewer-allocations branch from a1665b7 to 85d0c5d Compare November 5, 2023 16:18
jsha added 2 commits November 5, 2023 16:18
This saves some allocations and copies of relatively large data.
split_at always creates a new Vec, but drain just moves bytes within the
existing Vec.
@jsha jsha force-pushed the fewer-allocations branch from 85d0c5d to c4d279b Compare November 6, 2023 00:18
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

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

Nice!

I'll be curious to see if the CI run shows actual runtime performance.

It does, but pretty small ones.

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Nice finds!

@djc djc added this pull request to the merge queue Nov 6, 2023
Merged via the queue into rustls:main with commit e7a380f Nov 6, 2023
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.

4 participants