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

Slots copy is unnecessary for non parallel use #21

Open
RT2Code opened this issue Jan 30, 2019 · 3 comments
Open

Slots copy is unnecessary for non parallel use #21

RT2Code opened this issue Jan 30, 2019 · 3 comments

Comments

@RT2Code
Copy link

RT2Code commented Jan 30, 2019

Hello,

I noticed you are copying the slots when emit is called :

for( auto const& slot : copy_slots() ) {
	if( slot ) {
		value = func( value, slot( args... ) );
	}
}

I understand why it is necessary in a parallel context, but it's also happening with unsafe_signal, slowing drastically the call to this function for no benefits.

@NoAvailableAlias
Copy link

Slot copying does have a purpose even in single threaded use. It allows for slots to modify the parent signal such as removing itself from the signal as part of slot emission. Without copying this could run into iterator invalidation issues. Copying has other potential use cases in single threaded use as well.

Preferably slot copying could be opt-in with the use of a template policy. This would allow for the user to opt for high performance or opt into supporting these additional use cases at the expense of performance.

@RT2Code
Copy link
Author

RT2Code commented Feb 12, 2019

Ah, I missed that indeed. But as you said, it would be preferable to give the possibility for the user to disable this behavior because it is not always needed and the performance impact is huge.

@dosena
Copy link

dosena commented Dec 16, 2020

allows for slots to modify the parent signal such as removing itself from the signal as part of slot emission

Since the only way for a slot to remove itself is to use connection.disconnect() and because connection is non-copyable, the connection has to be owned by something other than the slot.

This could result in poor encapsulation; you suddenly need a third entity in addition to the signal and slot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants