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

Add Event#hasListener, remove unused junk #3889

Open
wants to merge 5 commits into
base: 1.21
Choose a base branch
from

Conversation

apple502j
Copy link
Contributor

Should be self-descriptive.

Although this is cool, there is no reason to
keep this as part of shipped code.
@apple502j apple502j added the enhancement New feature or request label Jun 26, 2024
Copy link
Member

@modmuss50 modmuss50 left a comment

Choose a reason for hiding this comment

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

Please add some tests.

@apple502j apple502j requested a review from modmuss50 July 6, 2024 02:40
@modmuss50 modmuss50 added the last call If you care, make yourself heard right away! label Jul 6, 2024
*
* @return whether the event has any listeners
*/
public boolean hasListener() {
Copy link
Member

Choose a reason for hiding this comment

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

IMO this is a bad pattern. If you are concerned about allocation, reuse the context object. In typical modpacks, most events will be used and these checks will be pointless anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Thats a fair point, @apple502j did you have a specific use case in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

A usecase I had for this was for a deprecated event, where actually properly servicing it required setting up some expensive stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, not all context objects can be reused.

Copy link
Member

Choose a reason for hiding this comment

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

Can you link some specific examples?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/BasiqueEvangelist/ne-v-seti/blob/sanity-1.17/src/main/java/me/basiqueevangelist/nevseti/OfflineDataCache.java#L30
I guess I misremembered specifically how much it would take to service this event, but I think it will still be useful for events that are deprecated and require running extra logic to run their invokers

@apple502j apple502j requested a review from modmuss50 July 20, 2024 18:27
*
* @return whether the event has any listeners
*/
public boolean hasListener() {
Copy link
Member

Choose a reason for hiding this comment

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

This is not resolved, please don't mark it as resolved.

@modmuss50
Copy link
Member

Still wating on a good usecase for this, in places where it matter we already re-use a context object, and firing an event with no listeners should have little overhead.

@apple502j
Copy link
Contributor Author

I think I had some events in my mind when I filed this PR, I need to figure that out again.

@apple502j
Copy link
Contributor Author

Events with non-zero invocation cost

  • RegSync: Remap event constructs RemapStateImpl. Very negligible as this is called only once per connection.
  • ItemGroupEvents: Involves creation of several objects. Once per startup, so doesn't really matter, unless Mojang decuples the number of items or something.
  • LootTableEvents: This might benefit from a check. An event (invoked per loot table) requires LootTable to be converted back to builder.

Will do a more thorough research later.

@melontini
Copy link

LootTableEvents: This might benefit from a check. An event (invoked per loot table) requires LootTable to be converted back to builder.

IMO this would only benefit if there was a separation between singular and wildcard events (like MODIFY_ALL, modify(RegistryKey) or modify(Predicate<LootTable>)).

With the current implementation, if a single mod wants to modify a single loot table, all the benefits of such a check disappear.

@Juuxel
Copy link
Member

Juuxel commented Aug 4, 2024

modify(Identifier) or modify(RegistryKey<LootTable>) would actually make sense for the API since most modifications are probably targeted to just a single loot table.

@modmuss50 modmuss50 removed the last call If you care, make yourself heard right away! label Oct 15, 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.

6 participants