Jump to content

Invoke method vs call it


Recommended Posts

Hi, i want some expert to answer me in this question. 

Which is faster:

1.  player.getObject().onDie(); 

2. Interface.invoke("onDie", player);       <-- Example syntax sucks afc.. just to make u understand

I think reflection is no that fast but does it affect performance if for example we do 5 times reflection upon doAttack ? This mean every a player hit it  does 5 invokes. 

 

PS. i did a berchmark in my code: 

It takes 46682 nanoseconds to invoke 5 methods. This mean  0.046682 milliseconds 

Edited by Ο Χάρος
Link to comment
Share on other sites

Added to the fact it's uglier to read, it's also slower (but not noticeable) to invoke rather than calling it.

If you got no specific use to use invoke, dump it.

Edited by Tryskell
Link to comment
Share on other sites

20 minutes ago, Tryskell said:

Added to the fact it's uglier to read, it's also slower (but not noticeable) to invoke rather than calling it.

If you got no specific use to use invoke, dump it.

It's lot of classes, lots of work and im thinking if it worh the work for just few nanoseconds.. it's really 0.006 max 0.1 millisecond difference to do 4 classes

Link to comment
Share on other sites

41 minutes ago, SweeTs said:

Access shitcoding since ever, so.. :D

Oh cum on :3 how many account you have O.o

i got chat banned :(  Also shitcoding? i'm sure u remember codes i wrote year ago e.t.c

come on skype and try me bitch i dare u ;( CUM ONNNNNNNNNNNNN

Edited by Ο Χάρος
Link to comment
Share on other sites

  • 2 weeks later...

I really doubt you will have any problems. There is possibility that after a lot of usages, JVM will optimize your code so invoke will run a faster but never as fast as direct call. You might want to debug invoke method to see how many actions are done, you wont be able to monitor native method call though. In Java 8 with Functional Interfaces most likely you dont really need to use reflection, so giving us what you really want to do and we might give you better solution.

Next thing is that you need to make a lot of catches & in future while you or someone else changes name or parameters of doDie method, you will find out about this code when your server crashes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock