Wish Faster RaiseEvent

Discussion in 'Bugs & wishlist' started by Informatix, Jun 2, 2015.

  1. Informatix

    Informatix Expert Licensed User

    When a Java lib calls a sub with raiseEvent or raiseEvent2, there's a significant overhead compared to a direct call to a function in Java, that's why I write more and more parts of my games in Java to avoid calling B4A subs, especially in loops. The speed gain can attain 100%. In a lib like libGDX where some events are called every frame, the difference is easily noticeable. Is there any chance that the speed of calls to B4A subs is improved in future versions? Is it possible to give a higher priority to some calls?
     
    thedesolatesoul likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is currently a possible solution. However it only works with classes.
    It allows you to call B4A subs without reflection.

    B4A classes implement an interface named BA.SubDelegator.
    Your library could accept an object of this type and use it to raise the events (pass a class instance from B4A).

    In the B4A code you need to list the callable methods. It is done with this code:
    Code:
    Public Sub Initialize
       
    If False Then
         
    CallSub(Me, "test"'number of parameters is not important. This code will never be called.
         CallSub(Me, "Test_2")
       
    End If
    End Sub

    Sub test (i As Int)

    End Sub

    Sub Test_2

    End Sub
    Compile your app in release mode and you will see that it creates a method named callSub with the relevant subs.

    In your java code you can use this callSub method (part of the interface) instead of raiseEvent.
     
  3. Informatix

    Informatix Expert Licensed User

    Interesting to know. Unfortunately, the important events are in Main so it does not really help (unless there's a mean to add automatically the callSub method with its code for all public methods of the main class).
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    This mechanism will only work with B4A classes. It will not work with the main activity module. You can delegate the call from the class to the main activity. It will be still faster than raiseEvent though it is quite cumbersome.
     
    Informatix likes this.
  5. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Or instead create an activity (in the library): MyActivity implements BA.SubDelegator and in the B4A activity use #Extends: MyActivity ?
    EDIT: Probably wont work as it requires a B4A compile pass to generate the callsub method.
     
  6. Informatix

    Informatix Expert Licensed User

    I wanted a solution that is not too cumbersome for B4A users, e.g. to improve the speed of libGDX when a lot of events are raised. But the current solution is not suitable for most users so I will wait for an improvement in future versions. For my own code, I can write parts in Java so I'm not 100% concerned.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice