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

feat: add signal aliases on SignalGroup #299

Merged
merged 17 commits into from
Mar 22, 2024

Conversation

getzze
Copy link
Contributor

@getzze getzze commented Mar 12, 2024

Split from #265
solves #261

Add a keyword argument to SignalGroupDescriptor to specify signal aliases (if the alias is None, no signal is created for this field). The signal aliases table is stored in the SignalGroup class (or subclass).

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (33a6f20) to head (cfa8f71).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #299   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         1972      2009   +37     
=========================================
+ Hits          1972      2009   +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Mar 12, 2024

CodSpeed Performance Report

Merging #299 will improve performances by 14.18%

Comparing getzze:signal-aliases (cfa8f71) with main (33a6f20)

Summary

⚡ 1 improvements
✅ 65 untouched benchmarks

Benchmarks breakdown

Benchmark main getzze:signal-aliases Change
test_emit_time[lambda-2] 128.2 µs 112.3 µs +14.18%

@getzze
Copy link
Contributor Author

getzze commented Mar 12, 2024

All tests pass, there is just a small performance regression. This is good to review.

@tlambert03
Copy link
Member

at first glance I'm impressed! will review more thoroughly soon. thanks again @getzze

Comment on lines 414 to 418
def get_signal_by_alias(self, name: str) -> SignalInstance | None:
sig_name = self._psygnal_aliases.get(name, name)
if sig_name is None or sig_name not in self:
return None
return self[sig_name]
Copy link
Member

Choose a reason for hiding this comment

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

hey @getzze, I think this is probably my only question (in an extremely nice PR). I can see why you did it this way as opposed to modifing __getitem__ It allows someone to query both the alias name and the original name. Do you think that's important? (I assume so, since you've been giving it a lot of thought and opted for this).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey, I think it can be removed, I mean inlined in evented_setattr, as it is only used there. And SignalGroup has one less method.

Copy link
Member

Choose a reason for hiding this comment

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

i do think that end-users should also be able to search by alias. but i guess the question is should they no longer be able to search by the original name? i.e. if I remove the method on SignalGroup, then end-users can no longer access the original names for an aliased signal, correct? are we ok with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a function instead of a method, with a new name get_signal_from_field.

@tlambert03
Copy link
Member

hey @getzze, I was able to avoid the slight performance regression with 64e2fb4

i know it was a very small one, but time to set attribute on evented models is probably the benchmark i am most concerned about keeping fast.

@getzze
Copy link
Contributor Author

getzze commented Mar 21, 2024

I see you had to do something quite convoluted to avoid the performance regression. But I'm glad you managed to make it work.
I don't know how to run the benchmarks in local, so I cannot test it, but maybe it could be as fast if with_aliases = bool(group._psygnal_aliases) is defined inside _setattr_and_emit_, before line 372. So it would simplify the code for maintenance.

I can commit the change I have in mind for the benchmark workflow to run if you want.

@tlambert03
Copy link
Member

maybe it could be as fast if with_aliases = bool(group._psygnal_aliases) is defined inside setattr_and_emit, before line 372. So it would simplify the code for maintenance.

I agree! go for it

I don't know how to run the benchmarks in local,

the codspeed benchmarks actually can't be run in local, (only the asv ones, and this wasn't a regression in those benchmarks)... so i just guessed it would help and got lucky :)

I can commit the change I have in mind for the benchmark workflow to run if you want.

sure!

@getzze
Copy link
Contributor Author

getzze commented Mar 21, 2024 via email

@getzze
Copy link
Contributor Author

getzze commented Mar 21, 2024

maybe it could be as fast if with_aliases = bool(group._psygnal_aliases) is defined inside _setattr_and_emit_

Nope...

@tlambert03
Copy link
Member

thanks @getzze. I'm still conflicted on how to present the fetching of signals by alias publicly. I don't like a top-level get_signal_from_field function. I removed and will just merge as is, without a public accessor. If you need one in the future, (i.e. outside of what the evented dataclass does for you already), let me know and we'll reconsider our options

@tlambert03 tlambert03 enabled auto-merge (squash) March 22, 2024 21:30
@tlambert03 tlambert03 merged commit f6cebcb into pyapp-kit:main Mar 22, 2024
54 checks passed
@getzze
Copy link
Contributor Author

getzze commented Mar 22, 2024

It sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants