omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Optimisation of GLES update times

    Pythonista
    3
    23
    15843
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • wradcliffe
      wradcliffe last edited by

      Got the latest repo and see the update to using cannon.js. If you run the test in Util/Physics/init.py there is some kind of background activity running that starts logging BULLET errors. It might be good to add some code there to shut down webview after the timing test. This seems to show that Cannon.js is running its own timer based routine even when you are not driving the simulation from Python code. The Canno engine seems significantly faster then Ammo.

      I now understand the code much better and see that the main.py routine drives the simulation by executing javascript on the webview. Subsequently, the webview calls back into python to update the postions and orientations of the objects. Since all the objects are moving for each frame, this overhead is fixed and there is probably not much you can do about it except to minimize the amount of data passed.

      It looks like you have done a major overhall of how the animation driver ("step") works. Instead of lots of calls to exec_js, you now have just a single "Physics.PhysicsWorld.js.eval_js('startUpdates();" call. This combined with the switch to Cannon seems to have given you a big speed increase.

      1 Reply Last reply Reply Quote 0
      • Cethric
        Cethric last edited by

        I cannot reproduces those errors (maybe just send the output of one) however try commenting out line 182 of Util/Physics/__init__.py. The program is meant to shutdown after exectution, however I have only added a function to do this I have not properly checked it to make sure it works correctly.

        I am not sure if I can minimise the data much more.

        The speed increase has been noticable thankfully however something that I don't get is that the function sendObjectData of line 53 in Util/Physics/CannonHelpers.js takes 1second when called from within javascript and only 100ms when called from python (the later however slows the python end down). Any ideas on that?

        1 Reply Last reply Reply Quote 0
        • wradcliffe
          wradcliffe last edited by

          I do not understand your comment about sendObjectData. I can see were it is called in the JS end of things and see that the timing will depend on the number of world.bodies. I don't see any places were it is called from python. From python all I see is the call to startUpdates using exec_js. I would like to duplicate your results first before theorizing so can you explain how to do the timing tests?

          1 Reply Last reply Reply Quote 0
          • Cethric
            Cethric last edited by

            In Util/Physics/CannonHelpers.js uncomment line 105, 129 and comment lines 127, 128, 134 and 135
            Then in main.py there is actually an issue which I just noticed. For this to work line 127 stays the same however without applying any of these changes line 127 should actually be within the if statement of Renderer.setup
            Then open the physics view. (The button on the top left of the GLKView next to the close button)

            1 Reply Last reply Reply Quote 0
            • Cethric
              Cethric last edited by

              I have updated the repo to reflect some of the changes here. I believe that I have got the physics as fast as possible within the limitations of what I can do... At about 60ms for the physics loop... (I would like it considerably faster but I'm not sure how)

              1 Reply Last reply Reply Quote 0
              • wradcliffe
                wradcliffe last edited by

                I notice that you added the ability to play with the number of objects that you send back to python using a slider in the Physics pane. There is an obvious hickup that happens in the value of "time to send to python" every so many iterations and the amount of overhead is defenitely quite high. Seems like there would be a benefit to being able to transmit the entire list of objects in single compressed string so that you could just make a single call. The best would be to figure out how to share the list of objects in memory and not transfer it at all, but I doubt there is a way to accomplish that.

                1 Reply Last reply Reply Quote 0
                • Cethric
                  Cethric last edited by

                  If I was using a ObjC JSContext then I could pass the objects around, however that would mean I could not have any callbacks as it is impossible to dynamically define them. That said if I create a UIWebView object I could access its JSContext object. That would mean creating another ObjC class as I believe using the ui module uses WKWebView. Is this correct @omz? or am I way off?

                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB last edited by

                    a WebVie appears to be SUIWebView. If you access the subviews of the objc object, it contains a UIWebView.

                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      w=ui.WebView()
                      objc_util.ObjCInstance(w).subviews()[0].valueForKeyPath_('documentView.webView.mainFrame.javaScriptContext')

                      result is a JSContext!

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by

                        Strangely, however, using setObject_ForKeyedSubscript seems to be MUCH slower than just passing a json object. Perhaps this is because the python to objc bridge has some overhead in creating a random object (using this with a json'd string is much faster). Also, I am not entirely sure how you would turn a generic object back into the python equivalent. Perhaps other data structures are faster, such as a generic ctypes Structure.

                        1 Reply Last reply Reply Quote 0
                        • Cethric
                          Cethric last edited by

                          @JonB using a JSON string is so much faster thankyou for the suggestion. I will update the repo soon after I clean a little bit of the code up....

                          1 Reply Last reply Reply Quote 0
                          • wradcliffe
                            wradcliffe last edited by

                            @JonB and @Cethric - this seems to imply that the JS runtime system is highly optimized for JSON encoding and decoding. That would not be a big surprise. The new method for transferring the data seems to also confirm that moving all the data in a single blob and with a single call back into python is the best strategy. I was thinking that the send_to_python call could also be running faster if the JSON method is handled via a http POST like mechanism rather then a http PUT. It certainly is interesting.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors