Repository navigation
[1/3] MessageDeframer: batch discard operations - #1595
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1595 +/- ##
==========================================
- Coverage 95.90% 95.89% -0.01%
==========================================
Files 78 78
Lines 16083 16188 +105
==========================================
+ Hits 15424 15524 +100
- Misses 659 664 +5 ☔ View full report in Codecov by Sentry. |
0a42bec to
816eecc
Compare
|
@djc I've addressed your comments in new commits. I'll squash when you are all happy with the final state. |
|
@djc anything else you would like to see addressed here or I should I go ahead and squash the commits? |
|
I prefer reviewing the squashed changes anyway. I'm pretty busy this week and focusing my rustls time on things that are blocking the 0.22 release so might take me a bit to get to this. |
816eecc to
3166291
Compare
|
squashed |
3166291 to
70eb6e2
Compare
|
updated to not use the |
70eb6e2 to
e671245
Compare
| .deframe(&mut self.deframer_buffer)? | ||
| .map(Message::try_from) | ||
| { | ||
| let mut to_discard = 0; |
There was a problem hiding this comment.
It looks like this would be simpler if to_discard (potentially with a different name) lived within the MessageDeframer and was reset by a call to a discarded(&mut self) -> usize like method.
There was a problem hiding this comment.
that's not a good place to track that because then one could use the same deframer with two different buffers and the same discard cursor would be used for both and that would be wrong (e.g. trigger a runtime panic). discard is associated to the buffer, not the deframer itself.
I have turned the discard field of DeframerSliceBuffer into a value (it was a reference) to remove the need for this caller-site stack / variable allocation.
e671245 to
ac7bbec
Compare
|
addressed the review comments |
ctz
left a comment
There was a problem hiding this comment.
this looks reasonable to me -- my only remaining question is whether we want to land this prior to cutting 0.22? looks like it gives a small but positive performance improvement -- but is the risk/reward there?
MessageDeframer: batch discard operationsMessageDeframer: batch discard operations
0.22 is out, so this concern is gone. apologies for how long that took; i hope we can make quick progress on these outstanding PRs now |
ac7bbec to
b8dbbc6
Compare
|
Both complaints from cargo-semver-checks are somewhat irrelevant; they are changes to types only available under |
b8dbbc6 to
5f760fa
Compare
56b5764 to
131f4df
Compare
djc
left a comment
There was a problem hiding this comment.
Would be good IMO to squash the final commit into the commit that originally introduced the DeframerBuffer trait.
| let discard = deframer_buffer.pending_discard(); | ||
| self.deframer_buffer.discard(discard); | ||
|
|
||
| match res?.map(Message::try_from) { |
There was a problem hiding this comment.
Is it correct to only yield the error after discarding here? I would find it more intuitive to have the ? directly on the deframe() call, but I don't have the context paged in for what kinds of errors the deframer will yield and whether we need to fuse it somehow?
(If we think this is the right way to do it, would be good to add a comment with some reasoning.)
There was a problem hiding this comment.
I don't have a proper answer for this.
The logic before this PR shows that deframe calls pop and doesn't discard anything itself. pop only discards on its happy path. So I don't see any evident reason to not do deframe()? instead.
However, I suspect that @japaric had a reason to do this whole let res = deframe() and then do res? as it is more complicated than just doing deframe()?.
So I think this is your call, we can leave as it is or we can change it.
There was a problem hiding this comment.
I think the best motivation for this sort of code are tests that demonstrate how things go wrong if one were to (for example) only do the discarding in the happy path. At a guess, the error fusing inside the deframer will make the distinction not observable at the public API level.
Tomorrow I think I'll write some extra tests for this; on a purely selfish level that is the way I find most effective to understand code -- reading doesn't do a lot for me.
| ) -> Result<Option<Deframed>, Error> { | ||
| self.inner | ||
| .pop(record_layer, negotiated_version, &mut self.buffer) | ||
| let mut deframer_buffer = self.buffer.borrow(); |
There was a problem hiding this comment.
Same here with the discard vs error returns.
There was a problem hiding this comment.
same answer as the previous one
131f4df to
a288b4c
Compare
done |
a288b4c to
f55b5eb
Compare
cpu
left a comment
There was a problem hiding this comment.
Looks great, thanks for your attention to the commit history. The DeframerBuffer const generic approach was a cool idea 👍
at @djc 's suggestion I have taken the
MessageDeframercommits in #1583 into their own PRI have also sneaked in an extra commit that batches
discardoperations (which may produce slight perf improvements in theConnectionAPI) that makes theMessageDeframeroperate on slices and it's part of the ongoing work on making decoding / decryption non-allocating / "in-place".