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

Allow to box messages in the channels implicitly #47

Merged
merged 3 commits into from
Jul 18, 2023

Conversation

vstakhov
Copy link
Contributor

This PR allows to box all messages when sending them over channels. The behaviour is controlled by attribute boxed_messages of the orchestra macro, for example:

#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError, boxed_messages=true)]
pub struct Orchestra {
	#[subsystem(consumes: MsgA, sends: [MsgB])]
	sub_a: AwesomeSubSysA,

	#[subsystem(consumes: MsgB, sends: [MsgA])]
	sub_b: AwesomeSubSysB,
}

This change is intended to be transparent for the orchestrated subsystems.

@vstakhov vstakhov added the enhancement New feature or request label Jun 20, 2023
@drahnr
Copy link
Collaborator

drahnr commented Jun 20, 2023

I think the approach would work, my question would be it might be less of a 🔨 to have it on a per message type, such that one could either annotate the message enum that a subsystem consumes with a proc-macro / individual fields / the subsystem;

#[orchestra::giftwrap(all)]
enum FooMessage {
}

#[orchestra::giftwrap]
enum BarMessage {

#[ribbon]
X(Fat),
}

(obviously the naming has to be adjusted)

or

#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError, boxed_messages=true)]
pub struct Orchestra {
	#[subsystem(consumes: boxed MsgA, sends: [MsgB])]
	sub_a: AwesomeSubSysA,

	#[subsystem(consumes: boxed MsgB, sends: [MsgA])]
	sub_b: AwesomeSubSysB,
}

such that the consumer defines the behavior of transparent boxing.

Mostly ideas, feel free to discard, the impl works.

@vstakhov
Copy link
Contributor Author

Benchmarks from my laptop (osx):

no jemalloc:

send boxed message u8   time:   [320.24 ns 328.55 ns 336.36 ns]
send unboxed message u8 time:   [285.09 ns 291.20 ns 296.45 ns]
send boxed message 1029 bytes time:   [738.99 ns 763.95 ns 788.70 ns] 
send unboxed message 1029 bytes time:   [615.58 ns 621.74 ns 628.62 ns]

preloaded jemalloc:

send boxed message u8   time:   [289.96 ns 297.19 ns 303.40 ns]
send unboxed message u8 time:   [252.18 ns 257.18 ns 261.48 ns]
send boxed message 1029 bytes time:   [386.75 ns 401.52 ns 415.99 ns]
send unboxed message 1029 bytes time:   [613.14 ns 619.94 ns 627.32 ns]

So almost no difference without jemalloc (boxed version is slightly slower in all cases) and significant difference when jemalloc is loaded.

@vstakhov
Copy link
Contributor Author

@drahnr I think we need to decide something about this PR as it is the base for others :) I'd say that implicit boxing is a good thing for the polkadot case (jemalloc and async-channel). Per-message boxing that you suggest is not very much different from the case where an orchestra user specifies explicitly a type of message equal to Box<T> with the only exception that this case is totally broken if multiple subsystems want to consume Box<T>. However, the former bug is also out of the scope for the suggested PR.

@vstakhov vstakhov requested a review from drahnr July 11, 2023 22:04
orchestra/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Collaborator

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

One dependency question.

Do we want to have an API to send i.e. a pre-boxed version of some messages?

Other than that LGTM (although I am not the greatest fan of the added complexity to orchestra. I'd have preferred to make it around the message types being sent, so orchestra can stay oblivious to the message type )

@vstakhov
Copy link
Contributor Author

Do we want to have an API to send i.e. a pre-boxed version of some messages?

Hum, what do you mean? By default, orchestra does not perform implicit boxing - it must be specified explicitly in orchestra macro. I like your idea about boxing for individual subsystems and that might be another improvement I think.

@vstakhov vstakhov requested a review from drahnr July 18, 2023 07:05
@vstakhov vstakhov merged commit 2ec50dd into master Jul 18, 2023
4 checks passed
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.

2 participants