Hi Wujimin

Could you write some code snippet for using the lambda in the EventBus?
As you said earlier, the EventBus uses reflection which may cause some
performance issue.
But I don't know how the lambda can to the same thing in EventBus.


Willem Jiang

Blog: http://willemjiang.blogspot.com (English)
          http://jnn.iteye.com  (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem

On Wed, May 16, 2018 at 8:49 AM, wjm wjm <[email protected]> wrote:

>  i have tested dynamic lambda, very fast, almost equals direct call
> so abandon interface solution  at last
> still use guava EventBus
> if cause performance problem, then rewrite a compatible EventBus
>
> static <T> T createLambda(Object instance, Method instanceMethod,
> Class<?> functionalIntfCls)
>     throws Throwable {
>   Method intfMethod = findAbstractMethod(functionalIntfCls);
>
>   MethodType invokedType = MethodType.methodType(functionalIntfCls,
> instance.getClass());
>   MethodType intfMethodType =
> MethodType.methodType(intfMethod.getReturnType(),
> intfMethod.getParameterTypes());
>   MethodHandle methodHandle = lookup.unreflect(instanceMethod);
>   MethodType instanceMethodType = MethodType
>       .methodType(instanceMethod.getReturnType(),
> instanceMethod.getParameterTypes());
>
>   CallSite callSite = LambdaMetafactory.metafactory(
>       lookup,
>       intfMethod.getName(),
>       invokedType,
>       intfMethodType,
>       methodHandle,
>       instanceMethodType
>   );
>   //noinspection unchecked
>   return (T) callSite.getTarget().invoke(instance);
> }
>
>
>
> Round 0:
> direct:281
> reflect:341
> lambda:297
>
> Round 1:
> direct:262
> reflect:329
> lambda:263
>
> Round 2:
> direct:259
> reflect:321
> lambda:259
>
> Round 3:
> direct:259
> reflect:322
> lambda:261
>
> Round 4:
> direct:255
> reflect:325
> lambda:259
>
>
> 2018-05-14 11:00 GMT+08:00 wjm wjm <[email protected]>:
>
> > no instanceOf, no reflection during invoke
> > only get all interfaces from class when register a listener instance
> >
> > 2018-05-14 10:43 GMT+08:00 Willem Jiang <[email protected]>:
> >
> >> We need to limited the events types, otherwise it could cause some
> trouble
> >> if the listener interesting bunch of events.
> >> BTW, can we set the event class type to the Listener?
> >> I'm not sure how much efforts the instanceOf operation need.
> >> If it is as heavy as the reflection, we may be back to the start point.
> >>
> >>
> >> Willem Jiang
> >>
> >> Blog: http://willemjiang.blogspot.com (English)
> >>           http://jnn.iteye.com  (Chinese)
> >> Twitter: willemjiang
> >> Weibo: 姜宁willem
> >>
> >> On Mon, May 14, 2018 at 9:25 AM, wjm wjm <[email protected]> wrote:
> >>
> >> > class XxxListener implements AListener,BListener...{
> >> > }
> >> >
> >> > All listener interfaces extends from a center type
> >> > when we got a listener instance, then loop all it's interfaces and
> cache
> >> > them
> >> > when publish event, get listener instance from cache and invoke
> >> >
> >> > 2018-05-13 10:07 GMT+08:00 Willem Jiang <[email protected]>:
> >> >
> >> > > +1 for the performance enhancement.
> >> > > If it make sense we could let the event listener to subscribe a
> center
> >> > type
> >> > > of event.
> >> > > My question is how can we describe the event that the listener is
> >> > > interested?
> >> > >
> >> > >
> >> > >
> >> > > Willem Jiang
> >> > >
> >> > > Blog: http://willemjiang.blogspot.com (English)
> >> > >           http://jnn.iteye.com  (Chinese)
> >> > > Twitter: willemjiang
> >> > > Weibo: 姜宁willem
> >> > >
> >> > > On Sat, May 12, 2018 at 4:31 PM, wjm wjm <[email protected]> wrote:
> >> > >
> >> > > > currently we publish invocation start/startProcess/finish event
> for
> >> > every
> >> > > > invocation
> >> > > > now event based on guava EventBus
> >> > > > it's easy to use.
> >> > > >
> >> > > > but EventBus based on reflection, performance is not the best.
> >> > > > in the furture maybe we will add more invocaiton event, and more
> >> module
> >> > > > will subscribe invocation event.
> >> > > >
> >> > > > so i want to publish invocation event, change from EventBus event
> to
> >> > > event
> >> > > > listener loaded by SPI.
> >> > > >
> >> > > > what's you suggestion?
> >> > > >
> >> > >
> >> >
> >>
> >
> >
>

Reply via email to