Store `Feature` flags in line rather than on the heap by default (without increasing their size)
In a running LDK instance we generally have a ton of Features objects flying around, including ones per channel/peer in the NetworkGraph, ones per channel/peer in
Channel/ChannelManager, and ones inside of BOLT 11/12 Invoices.
Thus, its useful to avoid unecessary allocations in them to reduce heap fragmentation.
Luckily, Features generally don't have more than 15 bytes worth of flags, and because Vec has a NonNull pointer we can actually wrap a vec in a two-variant enum with zero additional space penalty.
While this patch leaves actually deserializing Features without allocating as a future exercise, immediately releasing the allocation is much better than holding it, and Features constructed through repeated set_* calls benefit from avoiding the Vec entirely.
👋 Thanks for assigning @tnull as a reviewer! I'll wait for their review and will help manage the review process. Once they submit their review, I'll check if a second reviewer would be helpful.
🔔 1st Reminder
Hey @valentinewallace! This PR has been waiting for your review. Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.
Seems CI is stuck here?
Went ahead and squashed to see if CI will run again.
Also made clippy happy:
$ git diff-tree -U2 a07c020d4 4a841aac3diff --git a/lightning-types/src/features.rs b/lightning-types/src/features.rs
index 804083d65..d97347b47 100644
--- a/lightning-types/src/features.rs
+++ b/lightning-types/src/features.rs
@@ -816,5 +816,5 @@ impl DerefMut for FeatureFlags {
impl PartialOrd for FeatureFlags {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
- self.deref().partial_cmp(other.deref())
+ Some(self.cmp(other))
}
}
Codecov Report
Attention: Patch coverage is 90.09901% with 10 lines in your changes missing coverage. Please review.
Project coverage is 90.99%. Comparing base (
85185d8) to head (f491278). Report is 98 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| lightning-types/src/features.rs | 90.09% | 6 Missing and 4 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #3730 +/- ##
==========================================
+ Coverage 89.11% 90.99% +1.87%
==========================================
Files 156 158 +2
Lines 123514 138442 +14928
Branches 123514 138442 +14928
==========================================
+ Hits 110070 125970 +15900
+ Misses 10762 9853 -909
+ Partials 2682 2619 -63
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
🔔 1st Reminder
Hey @tnull! This PR has been waiting for your review. Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.
🔔 2nd Reminder
Hey @tnull! This PR has been waiting for your review. Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.
🔔 3rd Reminder
Hey @tnull! This PR has been waiting for your review. Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.
Squashed without further changes.