-
Notifications
You must be signed in to change notification settings - Fork 427
Description
Core types have excessive generic parameters that harm maintainability:
ChannelManager- 10 type parametersOnionMessenger- 9 type parametersPeerManager- 8 type parameters
This makes certain refactors nearly impossible. Adding a new dependency to ChannelManager means threading a new generic through dozens of impl blocks, all their where clauses, and every downstream consumer. The friction discourages improvements that would otherwise be straightforward.
Performance concerns are overstated
The traits behind these parameters do I/O, networking, disk access, and cryptographic operations - all measured in microseconds to milliseconds. A vtable call costs ~1 nanosecond. The overhead is unmeasurable noise.
There are no hot paths here. Lightning nodes are I/O-bound, not CPU-bound. No one has ever profiled LDK and found vtable dispatch as a bottleneck - because it isn't one.
Precedent
DynSigner already exists in the codebase and demonstrates that dynamic dispatch works fine for signing operations - one of the more performance-sensitive areas.
Proposal
Start with ChannelManager and convert object-safe traits to dyn. Candidates:
BroadcasterInterfaceFeeEstimatorLoggerEntropySource
Traits with associated types (Watch, SignerProvider) or generic methods (Router) would need more work to become object-safe.
Expected outcome
Significantly reduce ChannelManager's type parameter count. Make future refactors tractable. No measurable performance change.
(co-authored by Claude)