Skip to content
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

Remove async-trait and Box<dyn Stream> #561

Closed
wants to merge 3 commits into from
Closed

Conversation

al8n
Copy link
Contributor

@al8n al8n commented Jan 18, 2024

Use impl async in return place to make most of code zero-cost abstraction.

This PR seems large, but there are no logic changes.

@al8n al8n added the enhancement New feature or request label Jan 18, 2024
@al8n al8n self-assigned this Jan 18, 2024
Comment on lines +24 to +34
fn proposal_chunks_stream(
&self,
view: View,
) -> impl Future<Output = impl Stream<Item = ProposalMsg> + Send + Sync + Unpin + 'static> + Send;
fn broadcast(&self, message: NetworkMessage) -> impl Future<Output = ()> + Send;
fn timeout_stream(
&self,
committee: &Committee,
view: View,
) -> impl Future<Output = impl Stream<Item = TimeoutMsg> + Send + Sync + Unpin + 'static> + Send;
fn timeout_qc_stream(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ufff, seeing this I do not think the code readability is actually improve and all...

Copy link
Contributor Author

@al8n al8n Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can directly use async keyword in the trait here, but it will show a warning. We can use #[allow(...)] to ignore the warnings. But still, readability is not as good as BoxStream and using async_trait. For performance, we avoid two Box allocations, one for Box stream, and another for Box future.

When implementing the trait, async keyword can be directly used, but in trait definition, by default, future fn is not Send.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can directly use async keyword in the trait here, but it will show a warning. We can use #[allow(...)] to ignore the warnings. But still, readability is not as good as BoxStream and using async_trait. For performance, we avoid two Box allocations, one for Box stream, and another for Box future.

For now performance is not an issue. I prefer clean code that messy one. I would like to know the opinion of the team on this but we are not in a hurry to change this. I remember reading that they will be improving it (remember something about forcing code to be send or not and that there is a macro for it).
IMO for now we can stall this.

Lets vote on it @bacv @youngjoon-lee @zeegomo
🟢 Merge 🔴 Keep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://crates.io/crates/trait-variant is the macro that can help, but will introduce an extra useless local trait.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://crates.io/crates/trait-variant is the macro that can help, but will introduce an extra useless local trait.

Yes, for that is more comfortable to keep the [async_trait] for now. This is introducing complexity instead of making it simpler. IMO

@al8n al8n closed this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants