-
Notifications
You must be signed in to change notification settings - Fork 962
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
fix(swarm): rewrite NetworkBehaviour
macro for more optimal code gen
#5486
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. |
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? 🙏 |
Description
I have rewritten
NetworkBehavior
derive 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
Either
s each need to store tags to make values addressable) and makes the enum dispatch constant. This also opened the opportunity to optimizeUpgradeInfoIterator
andConnectionHandler
into a state machine (they now remember where they stopped polling/iterating and skipped exhausted subhandlers/iterators). We could optimize theNetworkBehaviour
itself 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.