-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(swarm): rewrite NetworkBehaviour macro for more optimal code gen
#5486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
|
the compiler is now freaking out because the current macro is generating too nested types, this relates to the benchmark which uses swarm with up to 20 behaviors the command is: when I use experimental macros: the compiler can deal with it fine |
|
Should I switch all of the tests to the new macro? |
|
I think this is a great effort! I no longer maintain rust-libp2p but I am sure @jxs will be equally excited :) |
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.
Hi @jakubDoka this is amazing work, I am sorry for only being able to review this now. LGTM only some minor remarks left
Should I switch all of the tests to the new macro?
can we repeat them to experimental as well?
Thanks!
|
This pull request has merge conflicts. Could you please resolve them @jakubDoka? 🙏 |
|
@jxs it should be ready to merge. |
jxs
left a comment
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.
hi @jakubDoka we don't need a version bump nor CHANGELOG.md entries for test changes, as it doesn't affect the published version
|
Well, the ci was breaking so that got me a bit confused, how do I work around that? |
can you show what was breaking the CI? or rollback the |
0934d63 to
d18e536
Compare
|
This pull request has merge conflicts. Could you please resolve them @jakubDoka? 🙏 |
|
@jxs Sorry for the wait, I did not do this the moment I saw the message so I forgot about it, you can see the changelog checks are breaking now |
|
This pull request has merge conflicts. Could you please resolve them @jakubDoka? 🙏 |
|
This pull request has merge conflicts. Could you please resolve them @jakubDoka? 🙏 |
|
Thank you for this great effort @jakubDoka! I know I am a bit late to the party, but @jxs and I have been talking out of band about merging this PR, so I hope you don't mind my comments :)
I am unsure about this bit, at least in case of
So depending on how an event returned by one connection handler is handled on the layers above, it could be the case that an "earlier" handler can make progress again the next time we call This isn't necessarily a problem, but it does change the polling order from a formerly priority-based order (here there priority is the order in which the behaviors are declared) to a more Round-Robin style. Maybe that should be a separate PR/ discussion? Wdyt @jxs? |
Description
I have rewritten
NetworkBehaviorderive macro to generate more optimal and faster to compile code when using more behaviours (5, 10, 20), I noticed performance degrades even though I benchmarked the same load. This is related to #5026.New macro implementation generates enums and structs for each type implementing the traits instead of type-level linked lists. In many cases, this makes resulting types more compact (we store just one enum tag, whereas composed
Eithers each need to store tags to make values addressable) and makes the enum dispatch constant. This also opened the opportunity to optimizeUpgradeInfoIteratorandConnectionHandlerinto a state machine (they now remember where they stopped polling/iterating and skipped exhausted subhandlers/iterators). We could optimize theNetworkBehaviouritself too, but it would require users to put extra fields into the struct (this could be optional for BC).Change checklist
note: I misused the sync feature on github and it erased all my changes from the branch, thus pr #5303 was closed @jxs, @thomaseizinger.