-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Remove potentially too costly Packets::default() #14821
Conversation
Codecov Report
@@ Coverage Diff @@
## master #14821 +/- ##
=======================================
Coverage 80.3% 80.3%
=======================================
Files 403 403
Lines 102747 102734 -13
=======================================
- Hits 82551 82542 -9
+ Misses 20196 20192 -4 |
How about just making I don't think the benchmarks do much allocating in the timing sections. In general it generates the packet vector up front, then runs the code on that. |
@sakridge Thanks for review! That makes sense. I reverted most of changes. How does this pr look now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* Remove potentially too costly Packets::default() * Fix test... * Restore Packets::default() * Restore Packets::default() more (cherry picked from commit d6873b8)
* Remove potentially too costly Packets::default() * Fix test... * Restore Packets::default() * Restore Packets::default() more (cherry picked from commit d6873b8) Co-authored-by: Ryo Onodera <[email protected]>
Problem
I needed some cleanup while creating #14806 to ensure there is no similar issue.
The root problem is that current api is too easy to misuse. This follow-up pr is to fix the root cause and never reoccur similar issue in the future.
Summary of Changes
Packets::default()
. As far as I read the code, this not need to beDefault
. By convention,Default::default()
should be cheap butPakcets
violates that by over-allocating silently.Default
generally opens unbounded call-graph. So, I want to avoid it unless there is clear benefit/necessity to defineDefault
.Packets::for_test_and_bench
to aptly indicate the purpose. New name is intentionally verbose and indicates this shouldn't be used in the production code.to_packets
to#cfg(test)
, another source of potential cause of overallocation. It seems that production code doesn't actually need it as well.This pr's cleanup motto is that let's make the ultimate call-site decide the allocation behavior by explicit call of
to_packets_chunked
.This pr won't be back-ported to v1.4 intentionally. Maybe not worth do it.
Also, there is no functional change.
Fixes #