Skip to content

Orbit 0.3.0 - #9

Open
crosby-moe wants to merge 17 commits into
MeteorDevelopment:masterfrom
crosby-moe:orbit-2-electric-boogaloo
Open

Orbit 0.3.0#9
crosby-moe wants to merge 17 commits into
MeteorDevelopment:masterfrom
crosby-moe:orbit-2-electric-boogaloo

Conversation

@crosby-moe

@crosby-moe crosby-moe commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

API Changes:

  • Replaced IEventBus#registerLambdaFactory with IEventBus#registerLookup, what was before bus.registerLambdaFactory("com.example", (lookupInMethod, klass) -> (MethodHandles.Lookup) lookupInMethod.invoke(null, klass, MethodHandles.lookup())); is now just bus.registerLookup("com.example", MethodHandles.lookup());
  • Removed IListener#isStatic (LambdaListener#isStatic is still available)
  • Added IEventBus#isSubscribed(Object) to query if an object was subscribed though IEventBus#subscribe(Object)
  • Added IEventBus#isSubscribed(Class) to query if a class was subscribed though IEventBus#subscribe(Class)
  • Added IEventBus#isSubscribed(IListener) to query if a listener was subscribed though IEventBus#subscribe(IListener)

Internal Changes:

  • EventBus#listenerCache is now a synchronized IdentityHashMap instead of a ConcurrentHashMap accessed through iteration. Higher constant overhead, but much lower worst-case performance. Also fixes issues caused by mismatched identity hashing vs value hashing.
  • EventBus#listenerCache & EventBus#staticListenerCache now only hold listeners that are currently registered to the event bus. Caching for transient listeners moved to EventBus#LAMBDA_FACTORY_CACHE in a way that permits both object gc and class gc. Also reuses lambda factories when registering multiple lambda listeners of the same owning class to reduce hidden class creation and improve performance.
  • EventBus#lookupInfos are now ordered from longest to shortest package prefixes, such that a registered "com.example.specific" is not overshadowed when a "com.example" from another module was registered earlier.
  • Lowered the overhead for unsubscribing a class or an object, it does not create unused lambda listeners when unsubscribing objects that are not subscribed anymore.
  • Greatly improved subscription performance:
    • Lookup infos are now only fetched once per class instead of once per valid listener method within a class.
    • Non-static lambda listeners are no longer pointlessly created when subscribing a class.
    • Switched to MethodHandle#invokeExact for executor creation.
    • Reduced allocation rate & method nesting when creating listeners for large classes.

Regressions

  • Subsequent subscription of static listeners is now consistently slower. Previously, these LambdaListener instances were indefinitely stored in a cache. It would be possible to bring back this cache while also making it garbage collectable through a WeakHashMap, however it would also greatly increase the memory usage.
  • Subsequent subscription of instance listeners is also consistently slower for the same reason. However, initial subscription of instance listeners of the same class with a different owner is now faster and gives increased invocation performance.

Possible Improvements

  • It is possible to improve subscription speed again by using binary search insertion based on priority when adding listeners to the event bus.
  • It is possible to improve the performance of registering lookup infos by using binary search insertion based on prefix length.
  • It is possible to improve the worst-case of collecting lookup infos by using a prefix tree rather than iterating through a list, however the list is unlikely to grow large enough for this to be worth it.
  • It may be possible to improve subscription speed by using a record for LookupInfo and event posting speed for LambdaListener & ConsumerListener on java 16.

@crosby-moe

Copy link
Copy Markdown
Contributor Author

closes #3

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

Successfully merging this pull request may close these issues.

1 participant