codelv / enaml-native

Build native mobile apps in python with enaml
https://codelv.com/projects/enaml-native/
MIT License
259 stars 21 forks source link

Optimize byteplay #59

Closed frmdstryr closed 2 years ago

frmdstryr commented 6 years ago

Currently byteplay is 50% of the view loading time which accounts for about 25-30% of total app start time.

Cumulative time

02-06 20:14:46.641 7734-7751/com.codelv.thermostat I/pybridge:          

349319 function calls (343557 primitive calls) in 3.937 seconds

    Ordered by: cumulative time

    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    3.948    3.948 /data/user/0/com.codelv.thermostat/assets/python/main.py:36(main)
        1    0.000    0.000    3.205    3.205 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/app.py:131(start)
        1    0.000    0.000    3.205    3.205 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/loop.py:266(start)
        1    0.000    0.000    3.205    3.205 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/twisted/internet/base.py:1241(run)
        1    0.000    0.000    3.204    3.204 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/twisted/internet/base.py:1246(mainLoop)
        13    0.001    0.000    1.722    0.132 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/twisted/internet/base.py:839(runUntilCurrent)
        12    0.000    0.000    1.480    0.123 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/twisted/internet/epollreactor.py:206(doPoll)
        12    1.477    0.123    1.477    0.123 {method 'poll' of 'select.epoll' objects}
        1    0.000    0.000    1.203    1.203 /data/user/0/com.codelv.thermostat/assets/python/main.py:55(load_view)
        1    0.000    0.000    1.035    1.035 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/import_hooks.py:124(load_module)
        1    0.003    0.003    1.019    1.019 /data/user/0/com.codelv.thermostat/assets/python/view.enaml:0()
        462    0.008    0.000    0.684    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/compiler_helpers.py:548(run_operator)
        1    0.000    0.000    0.657    0.657 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/android/app.py:71(__init__)
        1    0.000    0.000    0.657    0.657 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/app.py:116(__init__)
        1    0.000    0.000    0.655    0.655 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/app.py:213(init_error_handler)
        1    0.000    0.000    0.655    0.655 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/app.py:91(_default_loop)
        1    0.000    0.000    0.655    0.655 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/loop.py:33(default)
        1    0.001    0.001    0.647    0.647 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/loop.py:216(available)
        1    0.000    0.000    0.644    0.644 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/twisted/internet/reactor.py:32(<module>)
        1    0.001    0.001    0.643    0.643 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/twisted/internet/default.py:10(<module>)
        5    0.000    0.000    0.511    0.102 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/app.py:354(process_events)
        5    0.000    0.000    0.511    0.102 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/app.py:366(handle_event)
        469    0.083    0.000    0.510    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:646(to_code)
        107    0.003    0.000    0.393    0.004 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/operators.py:185(op_subscribe)
        107    0.003    0.000    0.390    0.004 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/operators.py:73(gen_tracer)
        1

By internal time

02-06 20:14:47.509 7734-7751/com.codelv.thermostat I/pybridge:          

349319 function calls (343557 primitive calls) in 3.937 seconds

            Ordered by: internal time

            ncalls  tottime  percall  cumtime  percall filename:lineno(function)
                12    1.477    0.123    1.477    0.123 {method 'poll' of 'select.epoll' objects}
             53159    0.095    0.000    0.096    0.000 {isinstance}
               469    0.083    0.000    0.510    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:646(to_code)
           275/274    0.074    0.000    0.169    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/atom/atom.py:176(__new__)
             10245    0.070    0.000    0.133    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:473(get_next_stacks)
               469    0.056    0.000    0.291    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:439(_compute_stacksize)
               469    0.053    0.000    0.090    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:319(from_code)
              5884    0.051    0.000    0.185    0.000 {method 'extend' of 'list' objects}
         1302/1301    0.049    0.000    0.051    0.000 {built-in method __new__ of type object at 0x98dfff80}
                 1    0.048    0.048    0.051    0.051 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/parse_tab/parsetab.py:4(<module>)
                 5    0.039    0.008    0.039    0.008 {method 'read' of 'file' objects}
             15969    0.037    0.000    0.062    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:231(isopcode)
            315/66    0.037    0.000    0.101    0.002 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/sre_parse.py:395(_parse)
                13    0.030    0.002    0.040    0.003 {imp.load_dynamic}
         8273/8258    0.027    0.000    0.095    0.000 {getattr}
               462    0.026    0.000    0.027    0.000 {method 'pack' of 'msgpack._packer.Packer' objects}
            642/62    0.026    0.000    0.064    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/sre_compile.py:64(_compile)
           376/375    0.025    0.000    0.102    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/zope/interface/interface.py:222(changed)
               618    0.025    0.000    0.123    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enamlnative/core/bridge.py:170(__call__)
               462    0.023    0.000    0.050    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/msgpack/__init__.py:41(packb)
              3472    0.022    0.000    0.026    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/sre_parse.py:193(__next)
              1831    0.021    0.000    0.021    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/expression_engine.py:101(copy)
                11    0.020    0.002    0.026    0.002 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/collections.py:293(namedtuple)
             11848    0.020    0.000    0.020    0.000 {method 'append' of 'array.array' objects}
              2170    0.018    0.000    0.024    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:668(index)
                22    0.017    0.001    0.096    0.004 {__import__}
       23203/22849    0.017    0.000    0.017    0.000 {len}
              1854    0.016    0.000    0.016    0.000 {zip}
              4227    0.016    0.000    0.018    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/byteplay.py:167(getse)
              3159    0.016    0.000    0.019    0.000 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/zope/interface/interface.py:518(__hash__)
            550/64    0.016    0.000    0.059    0.001 /home/jrm/.local/share/python-for-android/build/python-installs/enaml-native/enaml/core/comp
frmdstryr commented 6 years ago

@MatthieuDartiailh do you think byteplay could be written as a c/c++ extension to improve the speed? I'm willing to try if you think it is not too involved and worth the benefit. Thoughts?

MatthieuDartiailh commented 6 years ago

Honestly, I do not have much intuition here. It may allow some speed ups yes. If you want to try something like that, using cython may be an interesting alternative since you will be able to go in an incremental fashion (adding types) (And hand-written c-extensions are awful to write). By the way are you still running 0.9.8 ? Do you have any interest in supporting Python 3, or not ? Because this means more bytecode of course.

frmdstryr commented 6 years ago

Cython was actually my first thought and probably the route I'd try first, but wasn't sure since enaml uses all C++.

Right now it is still using 2.7 and 0.9.8 because when I first started your Python 3 support was not yet pulled in. I had tried updating a few months ago and found that the version of python that's precompiled for Android doesn't have lib2to3 (it's old) which is required by the future library.

But I do plan on upgrading and adding support for python3 at some point #46 .

MatthieuDartiailh commented 6 years ago

Enaml do use c++ rather than cython because @sccolbert was finding cython handling of reference counts sloppy at the time. I hope it has improved. Any way first experimenting with Cython make sense and if we find a huge gain, we will decide how to proceed next then.

MatthieuDartiailh commented 6 years ago

Any progress on this @frmdstryr ?

frmdstryr commented 6 years ago

Sorry not yet. Will let you know when I start it.

frmdstryr commented 6 years ago

@MatthieuDartiailh I worked on this a little. See the diff here. Just using cython and adding some cdef int's in various places seems to be giving about a 3-4x speedup, however it's pretty minimal in terms of time.

As initial attempt I just ran the tests and started a profiler in conftests.py and had it dump the stats with an atexit handler.

(venv) jrm@xps:~/Workspace/enaml$ py.test tests --cov enaml --cov-report xml -v | grep byteplay
4440/4346    0.924    0.000    4.499    0.001 /home/jrm/Workspace/enaml/enaml/core/byteplay/byteplay2.py:648(to_code)
     4440    0.416    0.000    2.377    0.001 /home/jrm/Workspace/enaml/enaml/core/byteplay/byteplay2.py:441(_compute_stacksize)
   292798    0.828    0.000    1.316    0.000 /home/jrm/Workspace/enaml/enaml/core/byteplay/byteplay2.py:475(get_next_stacks)

(venv) jrm@xps:~/Workspace/enaml$ py.test tests --cov enaml --cov-report xml -v | grep byteplay
     4346    1.073    0.000    1.073    0.000 {method 'to_code' of 'enaml.core.byteplay.byteplay2.Code' objects}
        1    0.002    0.002    0.004    0.004 /home/jrm/Workspace/enaml/enaml/core/byteplay/__init__.py:8(<module>)

Another application inkcut

(venv) jrm@xps:~/Workspace/inkcut$ python main.py | grep byteplay
1039/1037    0.021    0.000    0.107    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:648(to_code)
     1039    0.014    0.000    0.058    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:441(_compute_stacksize)
1039/1037    0.018    0.000    0.030    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:321(from_code)
    17395    0.015    0.000    0.027    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:475(get_next_stacks)
    27465    0.007    0.000    0.011    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:233(isopcode)
     1039    0.004    0.000    0.010    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:423(_compute_flags)
     8967    0.003    0.000    0.006    0.000 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/byteplay2.py:424(<genexpr>)
        1    0.005    0.005    0.006    0.006 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/__init__.py:8(<module>)

(venv) jrm@xps:~/Workspace/inkcut$ python main.py | grep byteplay
     1037    0.034    0.000    0.034    0.000 {method 'to_code' of 'enaml.core.byteplay.byteplay2.Code' objects}
        1    0.001    0.001    0.001    0.001 /home/jrm/Workspace/inkcut/venv/local/lib/python2.7/site-packages/enaml/core/byteplay/__init__.py:8(<module>)

I also tried this on the enaml-native demo android app and it made about a ~300ms (800ms to 500ms) speedup in the view loading (about 10% of total app startup).

I'm not sure if it's worth the extra complexity.

frmdstryr commented 6 years ago

Without cython

05-17 14:45:30.526 normal I/pybridge:          304384 function calls (298506 primitive calls) in 4.544 seconds
05-17 14:45:30.526 normal I/pybridge:    Ordered by: cumulative time
05-17 14:45:30.526 normal I/pybridge:    List reduced from 1804 to 541 due to restriction <0.29999999999999999>
05-17 14:45:30.526 normal I/pybridge:    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    4.556    4.556 ./main.py:17(main)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    4.188    4.188 ./site-packages/enamlnative/core/app.py:140(start)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    4.188    4.188 ./site-packages/enamlnative/core/loop.py:62(start)
05-17 14:45:30.526 normal I/pybridge:         1    0.001    0.001    4.188    4.188 ./site-packages/enamlnative/core/eventloop/ioloop.py:840(start)
05-17 14:45:30.526 normal I/pybridge:        11    2.454    0.223    2.454    0.223 {method 'poll' of 'select.epoll' objects}
05-17 14:45:30.526 normal I/pybridge:        53    0.001    0.000    1.732    0.033 ./site-packages/enamlnative/core/eventloop/stack_context.py:290(null_wrapper)
05-17 14:45:30.526 normal I/pybridge:        48    0.000    0.000    1.732    0.036 ./site-packages/enamlnative/core/eventloop/ioloop.py:646(_run_callback)
05-17 14:45:30.526 normal I/pybridge:         1    0.001    0.001    1.187    1.187 ./main.py:27(load_view)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.756    0.756 ./site-packages/enaml/core/import_hooks.py:128(load_module)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.744    0.744 ./site-packages/enaml/compat.py:258(exec_)
05-17 14:45:30.526 normal I/pybridge:         1    0.002    0.002    0.744    0.744 /data/user/0/com.codelv.enamlnative.demo1/cache/view.enaml:1()
05-17 14:45:30.526 normal I/pybridge:       424    0.007    0.000    0.541    0.001 ./site-packages/enaml/core/compiler_helpers.py:551(run_operator)
05-17 14:45:30.526 normal I/pybridge:         4    0.000    0.000    0.514    0.128 ./site-packages/enamlnative/core/app.py:363(process_events)
05-17 14:45:30.526 normal I/pybridge:         4    0.000    0.000    0.513    0.128 ./site-packages/enamlnative/core/app.py:375(handle_event)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.511    0.511 ./site-packages/enamlnative/core/eventloop/concurrent.py:271(set_result)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.511    0.511 ./site-packages/enamlnative/core/eventloop/concurrent.py:320(_set_done)
05-17 14:45:30.526 normal I/pybridge:         2    0.000    0.000    0.511    0.256 ./site-packages/enamlnative/core/loop.py:183(safe_callback)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.511    0.511 ./site-packages/enamlnative/android/app.py:216(on_build_info)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.511    0.511 ./site-packages/enamlnative/android/app.py:235(_show_view)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.511    0.511 ./site-packages/enamlnative/core/app.py:278(get_view)
05-17 14:45:30.526 normal I/pybridge:         1    0.000    0.000    0.477    0.477 /data/user/0/com.codelv.enamlnative.demo1/cache/view.enaml:249(ContentView)
05-17 14:45:30.526 normal I/pybridge:       429    0.065    0.000    0.388    0.001 ./site-packages/enaml/core/byteplay/byteplay2.py:648(to_code)
05-17 14:45:30.527 normal I/pybridge:         1    0.001    0.001    0.385    0.385 ./site-packages/enaml/__init__.py:36(imports)
05-17 14:45:30.527 normal I/pybridge:         1    0.006    0.006    0.384    0.384 ./site-packages/enaml/core/import_hooks.py:8(<module>)
05-17 14:45:30.527 normal I/pybridge:     625/1    0.016    0.000    0.334    0.334 ./site-packages/enaml/widgets/toolkit_object.py:147(initialize)
05-17 14:45:30.527 normal I/pybridge:     640/1    0.015    0.000    0.322    0.322 ./site-packages/enaml/core/declarative.py:103(initialize)
05-17 14:45:30.527 normal I/pybridge:         1    0.006    0.006    0.309    0.309 ./site-packages/enaml/core/parser/__init__.py:8(<module>)
05-17 14:45:30.527 normal I/pybridge:     52/32    0.001    0.000    0.278    0.009 ./site-packages/enaml/core/pattern.py:33(initialize)
05-17 14:45:30.527 normal I/pybridge:       357    0.006    0.000    0.261    0.001 ./site-packages/enaml/core/operators.py:49(gen_simple)
05-17 14:45:30.527 normal I/pybridge:   407/406    0.108    0.000    0.248    0.001 ./site-packages/atom/atom.py:182(__new__)
05-17 14:45:30.527 normal I/pybridge:         1    0.000    0.000    0.238    0.238 ./site-packages/enamlnative/android/app.py:71(__init__)
05-17 14:45:30.527 normal I/pybridge:         1    0.000    0.000    0.238    0.238 ./site-packages/enamlnative/core/app.py:125(__init__)
05-17 14:45:30.527 normal I/pybridge:        65    0.002    0.000    0.230    0.004 ./site-packages/enaml/core/operators.py:185(op_subscribe)
05-17 14:45:30.527 normal I/pybridge:        65    0.002    0.000    0.228    0.004 ./site-packages/enaml/core/operators.py:73(gen_tracer)
05-17 14:45:30.527 normal I/pybridge:       429    0.044    0.000    0.219    0.001 ./site-packages/enaml/core/byteplay/byteplay2.py:441(_compute_stacksize)
05-17 14:45:30.527 normal I/pybridge:       326    0.006    0.000    0.207    0.001 ./site-packages/enaml/core/operators.py:127(op_simple)
05-17 14:45:30.527 normal I/pybridge:      92/3    0.004    0.000    0.204    0.068 ./site-packages/enaml/widgets/toolkit_object.py:201(activate_proxy)
05-17 14:45:30.527 normal I/pybridge:        38    0.000    0.000    0.202    0.005 ./re.py:192(compile)
05-17 14:45:30.527 normal I/pybridge:        38    0.003    0.000    0.202    0.005 ./re.py:230(_compile)
05-17 14:45:30.527 normal I/pybridge:        38    0.001    0.000    0.198    0.005 ./sre_compile.py:567(compile)
05-17 14:45:30.527 normal I/pybridge:         1    0.000    0.000    0.189    0.189 ./site-packages/enaml/core/parser/base_parser.py:206(__init__)
05-17 14:45:30.527 normal I/pybridge:       625    0.008    0.000    0.182    0.000 ./site-packages/enaml/application.py:351(create_proxy)
05-17 14:45:30.527 normal I/pybridge:         1    0.001    0.001    0.173    0.173 ./site-packages/enamlnative/core/app.py:485(load_plugin_widgets)
05-17 14:45:30.527 normal I/pybridge:         1    0.017    0.017    0.172    0.172 ./site-packages/enamlnative/widgets/api.py:11(<module>)
05-17 14:45:30.527 normal I/pybridge:       625    0.008    0.000    0.170    0.000 ./site-packages/enaml/application.py:325(resolve_proxy_class)
05-17 14:45:30.527 normal I/pybridge:        92    0.001    0.000    0.163    0.002 ./site-packages/enaml/widgets/toolkit_object.py:218(activate_top_down)
05-17 14:45:30.527 normal I/pybridge:        92    0.001    0.000    0.162    0.002 ./site-packages/enamlnative/android/android_toolkit_object.py:69(activate_top_down)
05-17 14:45:30.527 normal I/pybridge:       970    0.005    0.000    0.155    0.000 ./site-packages/enaml/application.py:127(resolve)
05-17 14:45:30.527 normal I/pybridge:      4119    0.038    0.000    0.138    0.000 {method 'extend' of 'list' objects}
05-17 14:45:30.527 normal I/pybridge:         1    0.002    0.002    0.130    0.130 ./main.py:8(get_application)
05-17 14:45:30.527 normal I/pybridge:         1    0.005    0.005    0.126    0.126 ./site-packages/enamlnative/android/app.py:10(<module>)
05-17 14:45:30.527 normal I/pybridge:        38    0.001    0.000    0.116    0.003 ./sre_parse.py:725(parse)
05-17 14:45:30.527 normal I/pybridge:         1    0.011    0.011    0.113    0.113 ./site-packages/enaml/core/parser/base_parser.py:8(<module>)
05-17 14:45:30.527 normal I/pybridge:    218/38    0.006    0.000    0.112    0.003 ./sre_parse.py:336(_parse_sub)
05-17 14:45:30.527 normal I/pybridge:       117    0.007    0.000    0.112    0.001 ./site-packages/enaml/core/declarative_meta.py:111(__new__)
05-17 14:45:30.527 normal I/pybridge:   381/107    0.036    0.000    0.110    0.001 ./sre_parse.py:414(_parse)
05-17 14:45:30.527 normal I/pybridge:        61    0.004    0.000    0.105    0.002 ./site-packages/enamlnative/android/android_view.py:143(init_widget)
05-17 14:45:30.527 normal I/pybridge:         1    0.001    0.001    0.103    0.103 ./site-packages/enamlnative/core/api.py:11(<module>)
05-17 14:45:30.528 normal I/pybridge:         1    0.001    0.001    0.102    0.102 ./site-packages/ply/yacc.py:3216(yacc)
05-17 14:45:30.528 normal I/pybridge:      7211    0.052    0.000    0.100    0.000 ./site-packages/enaml/core/byteplay/byteplay2.py:475(get_next_stacks)
05-17 14:45:30.528 normal I/pybridge:         1    0.001    0.001    0.100    0.100 ./site-packages/enamlnative/android/http.py:11(<module>)
05-17 14:45:30.528 normal I/pybridge:     48315    0.098    0.000    0.098    0.000 {isinstance}
05-17 14:45:30.528 normal I/pybridge:         1    0.004    0.004    0.095    0.095 ./site-packages/ply/yacc.py:62(<module>)
05-17 14:45:30.528 normal I/pybridge:        36    0.002    0.000    0.094    0.003 ./site-packages/enamlnative/android/android_button.py:82(init_widget)
05-17 14:45:30.528 normal I/pybridge:        44    0.001    0.000    0.092    0.002 ./site-packages/enamlnative/android/android_text_view.py:144(init_widget)
05-17 14:45:30.528 normal I/pybridge:         1    0.001    0.001    0.090    0.090 ./site-packages/enamlnative/core/http.py:10(<module>)
05-17 14:45:30.528 normal I/pybridge:         1    0.001    0.001    0.090    0.090 ./inspect.py:25(<module>)
05-17 14:45:30.528 normal I/pybridge:         1    0.000    0.000    0.086    0.086 ./site-packages/enaml/core/parser/base_lexer.py:498(__init__)
05-17 14:45:30.528 normal I/pybridge:         1    0.000    0.000    0.086    0.086 ./site-packages/ply/lex.py:862(lex)
05-17 14:45:30.528 normal I/pybridge:   639/142    0.007    0.000    0.086    0.001 ./site-packages/enaml/core/compiler_nodes.py:154(__call__)
05-17 14:45:30.528 normal I/pybridge:       429    0.047    0.000    0.085    0.000 ./site-packages/enaml/core/byteplay/byteplay2.py:321(from_code)
05-17 14:45:30.528 normal I/pybridge:   981/141    0.021    0.000    0.083    0.001 ./site-packages/enaml/core/compiler_nodes.py:177(populate)
05-17 14:45:30.528 normal I/pybridge:         1    0.005    0.005    0.082    0.082 ./httplib.py:67(<module>)
05-17 14:45:30.528 normal I/pybridge:         1    0.000    0.000    0.082    0.082 ./site-packages/ply/lex.py:211(readtab)
05-17 14:45:30.528 normal I/pybridge:        38    0.000    0.000    0.081    0.002 ./sre_compile.py:552(_code)
05-17 14:45:30.528 normal I/pybridge: 1747/1746    0.071    0.000    0.072    0.000 {built-in method __new__ of type object at 0x8db589c4}
05-17 14:45:30.528 normal I/pybridge:         1    0.001    0.001    0.072    0.072 ./tokenize.py:23(<module>)
05-17 14:45:30.528 normal I/pybridge:       380    0.014    0.000    0.069    0.000 ./site-packages/enamlnative/core/bridge.py:170(__call__)
05-17 14:45:30.528 normal I/pybridge:        20    0.001    0.000    0.068    0.003 {map}

with cython

05-17 14:46:30.350 cython I/pybridge:          205761 function calls (199883 primitive calls) in 4.249 seconds
05-17 14:46:30.350 cython I/pybridge:    Ordered by: cumulative time
05-17 14:46:30.350 cython I/pybridge:    List reduced from 1762 to 529 due to restriction <0.29999999999999999>
05-17 14:46:30.350 cython I/pybridge:    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
05-17 14:46:30.350 cython I/pybridge:         1    0.000    0.000    4.260    4.260 ./main.py:17(main)
05-17 14:46:30.350 cython I/pybridge:         1    0.000    0.000    3.897    3.897 ./site-packages/enamlnative/core/app.py:140(start)
05-17 14:46:30.350 cython I/pybridge:         1    0.000    0.000    3.897    3.897 ./site-packages/enamlnative/core/loop.py:62(start)
05-17 14:46:30.350 cython I/pybridge:         1    0.001    0.001    3.897    3.897 ./site-packages/enamlnative/core/eventloop/ioloop.py:840(start)
05-17 14:46:30.350 cython I/pybridge:        11    2.449    0.223    2.449    0.223 {method 'poll' of 'select.epoll' objects}
05-17 14:46:30.350 cython I/pybridge:        54    0.001    0.000    1.446    0.027 ./site-packages/enamlnative/core/eventloop/stack_context.py:290(null_wrapper)
05-17 14:46:30.350 cython I/pybridge:        49    0.000    0.000    1.445    0.029 ./site-packages/enamlnative/core/eventloop/ioloop.py:646(_run_callback)
05-17 14:46:30.350 cython I/pybridge:         1    0.000    0.000    0.896    0.896 ./main.py:27(load_view)
05-17 14:46:30.350 cython I/pybridge:         4    0.000    0.000    0.518    0.130 ./site-packages/enamlnative/core/app.py:363(process_events)
05-17 14:46:30.350 cython I/pybridge:         4    0.000    0.000    0.518    0.130 ./site-packages/enamlnative/core/app.py:375(handle_event)
05-17 14:46:30.350 cython I/pybridge:         1    0.000    0.000    0.516    0.516 ./site-packages/enamlnative/core/eventloop/concurrent.py:271(set_result)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.516    0.516 ./site-packages/enamlnative/core/eventloop/concurrent.py:320(_set_done)
05-17 14:46:30.351 cython I/pybridge:         2    0.000    0.000    0.516    0.258 ./site-packages/enamlnative/core/loop.py:183(safe_callback)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.516    0.516 ./site-packages/enamlnative/android/app.py:216(on_build_info)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.516    0.516 ./site-packages/enamlnative/android/app.py:235(_show_view)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.516    0.516 ./site-packages/enamlnative/core/app.py:278(get_view)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.463    0.463 ./site-packages/enaml/core/import_hooks.py:128(load_module)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.450    0.450 ./site-packages/enaml/compat.py:258(exec_)
05-17 14:46:30.351 cython I/pybridge:         1    0.001    0.001    0.450    0.450 /data/user/0/com.codelv.enamlnative.demo2/cache/view.enaml:1()
05-17 14:46:30.351 cython I/pybridge:         1    0.001    0.001    0.383    0.383 ./site-packages/enaml/__init__.py:36(imports)
05-17 14:46:30.351 cython I/pybridge:         1    0.004    0.004    0.382    0.382 ./site-packages/enaml/core/import_hooks.py:8(<module>)
05-17 14:46:30.351 cython I/pybridge:     625/1    0.010    0.000    0.336    0.336 ./site-packages/enaml/widgets/toolkit_object.py:147(initialize)
05-17 14:46:30.351 cython I/pybridge:     640/1    0.015    0.000    0.325    0.325 ./site-packages/enaml/core/declarative.py:103(initialize)
05-17 14:46:30.351 cython I/pybridge:         1    0.006    0.006    0.313    0.313 ./site-packages/enaml/core/parser/__init__.py:8(<module>)
05-17 14:46:30.351 cython I/pybridge:     52/32    0.001    0.000    0.281    0.009 ./site-packages/enaml/core/pattern.py:33(initialize)
05-17 14:46:30.351 cython I/pybridge:   407/406    0.112    0.000    0.250    0.001 ./site-packages/atom/atom.py:182(__new__)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.245    0.245 /data/user/0/com.codelv.enamlnative.demo2/cache/view.enaml:249(ContentView)
05-17 14:46:30.351 cython I/pybridge:       424    0.007    0.000    0.245    0.001 ./site-packages/enaml/core/compiler_helpers.py:551(run_operator)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.237    0.237 ./site-packages/enamlnative/android/app.py:71(__init__)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.237    0.237 ./site-packages/enamlnative/core/app.py:125(__init__)
05-17 14:46:30.351 cython I/pybridge:      92/3    0.005    0.000    0.207    0.069 ./site-packages/enaml/widgets/toolkit_object.py:201(activate_proxy)
05-17 14:46:30.351 cython I/pybridge:        38    0.000    0.000    0.204    0.005 ./re.py:192(compile)
05-17 14:46:30.351 cython I/pybridge:        38    0.003    0.000    0.203    0.005 ./re.py:230(_compile)
05-17 14:46:30.351 cython I/pybridge:        38    0.001    0.000    0.199    0.005 ./sre_compile.py:567(compile)
05-17 14:46:30.351 cython I/pybridge:         1    0.000    0.000    0.192    0.192 ./site-packages/enaml/core/parser/base_parser.py:206(__init__)
05-17 14:46:30.351 cython I/pybridge:       625    0.008    0.000    0.181    0.000 ./site-packages/enaml/application.py:351(create_proxy)
05-17 14:46:30.351 cython I/pybridge:         1    0.001    0.001    0.173    0.173 ./site-packages/enamlnative/core/app.py:485(load_plugin_widgets)
05-17 14:46:30.351 cython I/pybridge:         1    0.017    0.017    0.172    0.172 ./site-packages/enamlnative/widgets/api.py:11(<module>)
05-17 14:46:30.351 cython I/pybridge:       625    0.008    0.000    0.169    0.000 ./site-packages/enaml/application.py:325(resolve_proxy_class)
05-17 14:46:30.351 cython I/pybridge:        92    0.001    0.000    0.166    0.002 ./site-packages/enaml/widgets/toolkit_object.py:218(activate_top_down)
05-17 14:46:30.351 cython I/pybridge:        92    0.001    0.000    0.165    0.002 ./site-packages/enamlnative/android/android_toolkit_object.py:69(activate_top_down)
05-17 14:46:30.351 cython I/pybridge:       970    0.005    0.000    0.154    0.000 ./site-packages/enaml/application.py:127(resolve)
05-17 14:46:30.351 cython I/pybridge:         1    0.001    0.001    0.127    0.127 ./main.py:8(get_application)
05-17 14:46:30.351 cython I/pybridge:       429    0.125    0.000    0.125    0.000 {method 'to_code' of 'enaml.core.byteplay.byteplay2.Code' objects}
05-17 14:46:30.351 cython I/pybridge:         1    0.004    0.004    0.125    0.125 ./site-packages/enamlnative/android/app.py:10(<module>)
05-17 14:46:30.351 cython I/pybridge:        38    0.001    0.000    0.115    0.003 ./sre_parse.py:725(parse)
05-17 14:46:30.351 cython I/pybridge:       357    0.005    0.000    0.114    0.000 ./site-packages/enaml/core/operators.py:49(gen_simple)
05-17 14:46:30.351 cython I/pybridge:         1    0.011    0.011    0.114    0.114 ./site-packages/enaml/core/parser/base_parser.py:8(<module>)
05-17 14:46:30.352 cython I/pybridge:    218/38    0.006    0.000    0.113    0.003 ./sre_parse.py:336(_parse_sub)
05-17 14:46:30.352 cython I/pybridge:       117    0.007    0.000    0.112    0.001 ./site-packages/enaml/core/declarative_meta.py:111(__new__)
05-17 14:46:30.352 cython I/pybridge:   381/107    0.036    0.000    0.110    0.001 ./sre_parse.py:414(_parse)
05-17 14:46:30.352 cython I/pybridge:        61    0.004    0.000    0.105    0.002 ./site-packages/enamlnative/android/android_view.py:143(init_widget)
05-17 14:46:30.352 cython I/pybridge:         1    0.001    0.001    0.105    0.105 ./site-packages/enamlnative/core/api.py:11(<module>)
05-17 14:46:30.352 cython I/pybridge:         1    0.001    0.001    0.104    0.104 ./site-packages/ply/yacc.py:3216(yacc)
05-17 14:46:30.352 cython I/pybridge:         1    0.001    0.001    0.102    0.102 ./site-packages/enamlnative/android/http.py:11(<module>)
05-17 14:46:30.352 cython I/pybridge:       326    0.005    0.000    0.097    0.000 ./site-packages/enaml/core/operators.py:127(op_simple)
05-17 14:46:30.352 cython I/pybridge:         1    0.004    0.004    0.096    0.096 ./site-packages/ply/yacc.py:62(<module>)
05-17 14:46:30.352 cython I/pybridge:        36    0.002    0.000    0.093    0.003 ./site-packages/enamlnative/android/android_button.py:82(init_widget)
05-17 14:46:30.352 cython I/pybridge:         1    0.001    0.001    0.093    0.093 ./site-packages/enamlnative/core/http.py:10(<module>)
05-17 14:46:30.352 cython I/pybridge:   639/142    0.007    0.000    0.092    0.001 ./site-packages/enaml/core/compiler_nodes.py:154(__call__)
05-17 14:46:30.352 cython I/pybridge:         1    0.001    0.001    0.091    0.091 ./inspect.py:25(<module>)
05-17 14:46:30.352 cython I/pybridge:        44    0.001    0.000    0.090    0.002 ./site-packages/enamlnative/android/android_text_view.py:144(init_widget)
05-17 14:46:30.352 cython I/pybridge:   981/141    0.020    0.000    0.089    0.001 ./site-packages/enaml/core/compiler_nodes.py:177(populate)
05-17 14:46:30.352 cython I/pybridge:         1    0.000    0.000    0.088    0.088 ./site-packages/enaml/core/parser/base_lexer.py:498(__init__)
05-17 14:46:30.352 cython I/pybridge:         1    0.000    0.000    0.087    0.087 ./site-packages/ply/lex.py:862(lex)
05-17 14:46:30.352 cython I/pybridge:         1    0.005    0.005    0.084    0.084 ./httplib.py:67(<module>)
05-17 14:46:30.352 cython I/pybridge:        65    0.001    0.000    0.084    0.001 ./site-packages/enaml/core/operators.py:185(op_subscribe)
05-17 14:46:30.352 cython I/pybridge:         1    0.000    0.000    0.083    0.083 ./site-packages/ply/lex.py:211(readtab)
05-17 14:46:30.352 cython I/pybridge:        38    0.000    0.000    0.083    0.002 ./sre_compile.py:552(_code)
05-17 14:46:30.352 cython I/pybridge:        65    0.002    0.000    0.083    0.001 ./site-packages/enaml/core/operators.py:73(gen_tracer)
05-17 14:46:30.352 cython I/pybridge:         1    0.001    0.001    0.073    0.073 ./tokenize.py:23(<module>)
05-17 14:46:30.352 cython I/pybridge:       380    0.014    0.000    0.070    0.000 ./site-packages/enamlnative/core/bridge.py:170(__call__)
05-17 14:46:30.352 cython I/pybridge: 1747/1746    0.068    0.000    0.070    0.000 {built-in method __new__ of type object at 0x8db589c4}
05-17 14:46:30.352 cython I/pybridge:        20    0.001    0.000    0.070    0.003 {map}

Any ideas on what else could be optimized?

sccolbert commented 6 years ago

On a regular machine, enaml caches a .enamlc file (similar to a .pyc). If you can allow those to be generated and saved, you should only pay the byteplay cost once on first startup.

On Thu, May 17, 2018, 14:07 frmdstryr notifications@github.com wrote:

Without cython

05-17 14:45:30.526 normal I/pybridge: 304384 function calls (298506 primitive calls) in 4.544 seconds 05-17 14:45:30.526 normal I/pybridge: Ordered by: cumulative time 05-17 14:45:30.526 normal I/pybridge: List reduced from 1804 to 541 due to restriction <0.29999999999999999> 05-17 14:45:30.526 normal I/pybridge: ncalls tottime percall cumtime percall filename:lineno(function) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 4.556 4.556 ./main.py:17(main) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 4.188 4.188 ./site-packages/enamlnative/core/app.py:140(start) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 4.188 4.188 ./site-packages/enamlnative/core/loop.py:62(start) 05-17 14:45:30.526 normal I/pybridge: 1 0.001 0.001 4.188 4.188 ./site-packages/enamlnative/core/eventloop/ioloop.py:840(start) 05-17 14:45:30.526 normal I/pybridge: 11 2.454 0.223 2.454 0.223 {method 'poll' of 'select.epoll' objects} 05-17 14:45:30.526 normal I/pybridge: 53 0.001 0.000 1.732 0.033 ./site-packages/enamlnative/core/eventloop/stack_context.py:290(null_wrapper) 05-17 14:45:30.526 normal I/pybridge: 48 0.000 0.000 1.732 0.036 ./site-packages/enamlnative/core/eventloop/ioloop.py:646(_run_callback) 05-17 14:45:30.526 normal I/pybridge: 1 0.001 0.001 1.187 1.187 ./main.py:27(load_view) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.756 0.756 ./site-packages/enaml/core/import_hooks.py:128(loadmodule) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.744 0.744 ./site-packages/enaml/compat.py:258(exec) 05-17 14:45:30.526 normal I/pybridge: 1 0.002 0.002 0.744 0.744 /data/user/0/com.codelv.enamlnative.demo1/cache/view.enaml:1() 05-17 14:45:30.526 normal I/pybridge: 424 0.007 0.000 0.541 0.001 ./site-packages/enaml/core/compiler_helpers.py:551(run_operator) 05-17 14:45:30.526 normal I/pybridge: 4 0.000 0.000 0.514 0.128 ./site-packages/enamlnative/core/app.py:363(process_events) 05-17 14:45:30.526 normal I/pybridge: 4 0.000 0.000 0.513 0.128 ./site-packages/enamlnative/core/app.py:375(handle_event) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.511 0.511 ./site-packages/enamlnative/core/eventloop/concurrent.py:271(set_result) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.511 0.511 ./site-packages/enamlnative/core/eventloop/concurrent.py:320(_set_done) 05-17 14:45:30.526 normal I/pybridge: 2 0.000 0.000 0.511 0.256 ./site-packages/enamlnative/core/loop.py:183(safe_callback) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.511 0.511 ./site-packages/enamlnative/android/app.py:216(on_build_info) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.511 0.511 ./site-packages/enamlnative/android/app.py:235(_show_view) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.511 0.511 ./site-packages/enamlnative/core/app.py:278(get_view) 05-17 14:45:30.526 normal I/pybridge: 1 0.000 0.000 0.477 0.477 /data/user/0/com.codelv.enamlnative.demo1/cache/view.enaml:249(ContentView) 05-17 14:45:30.526 normal I/pybridge: 429 0.065 0.000 0.388 0.001 ./site-packages/enaml/core/byteplay/byteplay2.py:648(to_code) 05-17 14:45:30.527 normal I/pybridge: 1 0.001 0.001 0.385 0.385 ./site-packages/enaml/init.py:36(imports) 05-17 14:45:30.527 normal I/pybridge: 1 0.006 0.006 0.384 0.384 ./site-packages/enaml/core/import_hooks.py:8() 05-17 14:45:30.527 normal I/pybridge: 625/1 0.016 0.000 0.334 0.334 ./site-packages/enaml/widgets/toolkit_object.py:147(initialize) 05-17 14:45:30.527 normal I/pybridge: 640/1 0.015 0.000 0.322 0.322 ./site-packages/enaml/core/declarative.py:103(initialize) 05-17 14:45:30.527 normal I/pybridge: 1 0.006 0.006 0.309 0.309 ./site-packages/enaml/core/parser/init.py:8() 05-17 14:45:30.527 normal I/pybridge: 52/32 0.001 0.000 0.278 0.009 ./site-packages/enaml/core/pattern.py:33(initialize) 05-17 14:45:30.527 normal I/pybridge: 357 0.006 0.000 0.261 0.001 ./site-packages/enaml/core/operators.py:49(gen_simple) 05-17 14:45:30.527 normal I/pybridge: 407/406 0.108 0.000 0.248 0.001 ./site-packages/atom/atom.py:182(new) 05-17 14:45:30.527 normal I/pybridge: 1 0.000 0.000 0.238 0.238 ./site-packages/enamlnative/android/app.py:71(init) 05-17 14:45:30.527 normal I/pybridge: 1 0.000 0.000 0.238 0.238 ./site-packages/enamlnative/core/app.py:125(init) 05-17 14:45:30.527 normal I/pybridge: 65 0.002 0.000 0.230 0.004 ./site-packages/enaml/core/operators.py:185(op_subscribe) 05-17 14:45:30.527 normal I/pybridge: 65 0.002 0.000 0.228 0.004 ./site-packages/enaml/core/operators.py:73(gen_tracer) 05-17 14:45:30.527 normal I/pybridge: 429 0.044 0.000 0.219 0.001 ./site-packages/enaml/core/byteplay/byteplay2.py:441(_compute_stacksize) 05-17 14:45:30.527 normal I/pybridge: 326 0.006 0.000 0.207 0.001 ./site-packages/enaml/core/operators.py:127(op_simple) 05-17 14:45:30.527 normal I/pybridge: 92/3 0.004 0.000 0.204 0.068 ./site-packages/enaml/widgets/toolkit_object.py:201(activate_proxy) 05-17 14:45:30.527 normal I/pybridge: 38 0.000 0.000 0.202 0.005 ./re.py:192(compile) 05-17 14:45:30.527 normal I/pybridge: 38 0.003 0.000 0.202 0.005 ./re.py:230(_compile) 05-17 14:45:30.527 normal I/pybridge: 38 0.001 0.000 0.198 0.005 ./sre_compile.py:567(compile) 05-17 14:45:30.527 normal I/pybridge: 1 0.000 0.000 0.189 0.189 ./site-packages/enaml/core/parser/base_parser.py:206(init) 05-17 14:45:30.527 normal I/pybridge: 625 0.008 0.000 0.182 0.000 ./site-packages/enaml/application.py:351(create_proxy) 05-17 14:45:30.527 normal I/pybridge: 1 0.001 0.001 0.173 0.173 ./site-packages/enamlnative/core/app.py:485(load_plugin_widgets) 05-17 14:45:30.527 normal I/pybridge: 1 0.017 0.017 0.172 0.172 ./site-packages/enamlnative/widgets/api.py:11() 05-17 14:45:30.527 normal I/pybridge: 625 0.008 0.000 0.170 0.000 ./site-packages/enaml/application.py:325(resolve_proxy_class) 05-17 14:45:30.527 normal I/pybridge: 92 0.001 0.000 0.163 0.002 ./site-packages/enaml/widgets/toolkit_object.py:218(activate_top_down) 05-17 14:45:30.527 normal I/pybridge: 92 0.001 0.000 0.162 0.002 ./site-packages/enamlnative/android/android_toolkit_object.py:69(activate_top_down) 05-17 14:45:30.527 normal I/pybridge: 970 0.005 0.000 0.155 0.000 ./site-packages/enaml/application.py:127(resolve) 05-17 14:45:30.527 normal I/pybridge: 4119 0.038 0.000 0.138 0.000 {method 'extend' of 'list' objects} 05-17 14:45:30.527 normal I/pybridge: 1 0.002 0.002 0.130 0.130 ./main.py:8(get_application) 05-17 14:45:30.527 normal I/pybridge: 1 0.005 0.005 0.126 0.126 ./site-packages/enamlnative/android/app.py:10() 05-17 14:45:30.527 normal I/pybridge: 38 0.001 0.000 0.116 0.003 ./sre_parse.py:725(parse) 05-17 14:45:30.527 normal I/pybridge: 1 0.011 0.011 0.113 0.113 ./site-packages/enaml/core/parser/base_parser.py:8() 05-17 14:45:30.527 normal I/pybridge: 218/38 0.006 0.000 0.112 0.003 ./sre_parse.py:336(_parse_sub) 05-17 14:45:30.527 normal I/pybridge: 117 0.007 0.000 0.112 0.001 ./site-packages/enaml/core/declarative_meta.py:111(new) 05-17 14:45:30.527 normal I/pybridge: 381/107 0.036 0.000 0.110 0.001 ./sre_parse.py:414(_parse) 05-17 14:45:30.527 normal I/pybridge: 61 0.004 0.000 0.105 0.002 ./site-packages/enamlnative/android/android_view.py:143(init_widget) 05-17 14:45:30.527 normal I/pybridge: 1 0.001 0.001 0.103 0.103 ./site-packages/enamlnative/core/api.py:11() 05-17 14:45:30.528 normal I/pybridge: 1 0.001 0.001 0.102 0.102 ./site-packages/ply/yacc.py:3216(yacc) 05-17 14:45:30.528 normal I/pybridge: 7211 0.052 0.000 0.100 0.000 ./site-packages/enaml/core/byteplay/byteplay2.py:475(get_next_stacks) 05-17 14:45:30.528 normal I/pybridge: 1 0.001 0.001 0.100 0.100 ./site-packages/enamlnative/android/http.py:11() 05-17 14:45:30.528 normal I/pybridge: 48315 0.098 0.000 0.098 0.000 {isinstance} 05-17 14:45:30.528 normal I/pybridge: 1 0.004 0.004 0.095 0.095 ./site-packages/ply/yacc.py:62() 05-17 14:45:30.528 normal I/pybridge: 36 0.002 0.000 0.094 0.003 ./site-packages/enamlnative/android/android_button.py:82(init_widget) 05-17 14:45:30.528 normal I/pybridge: 44 0.001 0.000 0.092 0.002 ./site-packages/enamlnative/android/android_text_view.py:144(init_widget) 05-17 14:45:30.528 normal I/pybridge: 1 0.001 0.001 0.090 0.090 ./site-packages/enamlnative/core/http.py:10() 05-17 14:45:30.528 normal I/pybridge: 1 0.001 0.001 0.090 0.090 ./inspect.py:25() 05-17 14:45:30.528 normal I/pybridge: 1 0.000 0.000 0.086 0.086 ./site-packages/enaml/core/parser/base_lexer.py:498(init) 05-17 14:45:30.528 normal I/pybridge: 1 0.000 0.000 0.086 0.086 ./site-packages/ply/lex.py:862(lex) 05-17 14:45:30.528 normal I/pybridge: 639/142 0.007 0.000 0.086 0.001 ./site-packages/enaml/core/compiler_nodes.py:154(call) 05-17 14:45:30.528 normal I/pybridge: 429 0.047 0.000 0.085 0.000 ./site-packages/enaml/core/byteplay/byteplay2.py:321(from_code) 05-17 14:45:30.528 normal I/pybridge: 981/141 0.021 0.000 0.083 0.001 ./site-packages/enaml/core/compiler_nodes.py:177(populate) 05-17 14:45:30.528 normal I/pybridge: 1 0.005 0.005 0.082 0.082 ./httplib.py:67() 05-17 14:45:30.528 normal I/pybridge: 1 0.000 0.000 0.082 0.082 ./site-packages/ply/lex.py:211(readtab) 05-17 14:45:30.528 normal I/pybridge: 38 0.000 0.000 0.081 0.002 ./sre_compile.py:552(_code) 05-17 14:45:30.528 normal I/pybridge: 1747/1746 0.071 0.000 0.072 0.000 {built-in method new of type object at 0x8db589c4} 05-17 14:45:30.528 normal I/pybridge: 1 0.001 0.001 0.072 0.072 ./tokenize.py:23() 05-17 14:45:30.528 normal I/pybridge: 380 0.014 0.000 0.069 0.000 ./site-packages/enamlnative/core/bridge.py:170(call) 05-17 14:45:30.528 normal I/pybridge: 20 0.001 0.000 0.068 0.003 {map}

with cython

05-17 14:46:30.350 cython I/pybridge: 205761 function calls (199883 primitive calls) in 4.249 seconds 05-17 14:46:30.350 cython I/pybridge: Ordered by: cumulative time 05-17 14:46:30.350 cython I/pybridge: List reduced from 1762 to 529 due to restriction <0.29999999999999999> 05-17 14:46:30.350 cython I/pybridge: ncalls tottime percall cumtime percall filename:lineno(function) 05-17 14:46:30.350 cython I/pybridge: 1 0.000 0.000 4.260 4.260 ./main.py:17(main) 05-17 14:46:30.350 cython I/pybridge: 1 0.000 0.000 3.897 3.897 ./site-packages/enamlnative/core/app.py:140(start) 05-17 14:46:30.350 cython I/pybridge: 1 0.000 0.000 3.897 3.897 ./site-packages/enamlnative/core/loop.py:62(start) 05-17 14:46:30.350 cython I/pybridge: 1 0.001 0.001 3.897 3.897 ./site-packages/enamlnative/core/eventloop/ioloop.py:840(start) 05-17 14:46:30.350 cython I/pybridge: 11 2.449 0.223 2.449 0.223 {method 'poll' of 'select.epoll' objects} 05-17 14:46:30.350 cython I/pybridge: 54 0.001 0.000 1.446 0.027 ./site-packages/enamlnative/core/eventloop/stack_context.py:290(null_wrapper) 05-17 14:46:30.350 cython I/pybridge: 49 0.000 0.000 1.445 0.029 ./site-packages/enamlnative/core/eventloop/ioloop.py:646(_run_callback) 05-17 14:46:30.350 cython I/pybridge: 1 0.000 0.000 0.896 0.896 ./main.py:27(load_view) 05-17 14:46:30.350 cython I/pybridge: 4 0.000 0.000 0.518 0.130 ./site-packages/enamlnative/core/app.py:363(process_events) 05-17 14:46:30.350 cython I/pybridge: 4 0.000 0.000 0.518 0.130 ./site-packages/enamlnative/core/app.py:375(handle_event) 05-17 14:46:30.350 cython I/pybridge: 1 0.000 0.000 0.516 0.516 ./site-packages/enamlnative/core/eventloop/concurrent.py:271(set_result) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.516 0.516 ./site-packages/enamlnative/core/eventloop/concurrent.py:320(_set_done) 05-17 14:46:30.351 cython I/pybridge: 2 0.000 0.000 0.516 0.258 ./site-packages/enamlnative/core/loop.py:183(safe_callback) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.516 0.516 ./site-packages/enamlnative/android/app.py:216(on_build_info) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.516 0.516 ./site-packages/enamlnative/android/app.py:235(_show_view) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.516 0.516 ./site-packages/enamlnative/core/app.py:278(get_view) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.463 0.463 ./site-packages/enaml/core/import_hooks.py:128(loadmodule) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.450 0.450 ./site-packages/enaml/compat.py:258(exec) 05-17 14:46:30.351 cython I/pybridge: 1 0.001 0.001 0.450 0.450 /data/user/0/com.codelv.enamlnative.demo2/cache/view.enaml:1() 05-17 14:46:30.351 cython I/pybridge: 1 0.001 0.001 0.383 0.383 ./site-packages/enaml/init.py:36(imports) 05-17 14:46:30.351 cython I/pybridge: 1 0.004 0.004 0.382 0.382 ./site-packages/enaml/core/import_hooks.py:8() 05-17 14:46:30.351 cython I/pybridge: 625/1 0.010 0.000 0.336 0.336 ./site-packages/enaml/widgets/toolkit_object.py:147(initialize) 05-17 14:46:30.351 cython I/pybridge: 640/1 0.015 0.000 0.325 0.325 ./site-packages/enaml/core/declarative.py:103(initialize) 05-17 14:46:30.351 cython I/pybridge: 1 0.006 0.006 0.313 0.313 ./site-packages/enaml/core/parser/init.py:8() 05-17 14:46:30.351 cython I/pybridge: 52/32 0.001 0.000 0.281 0.009 ./site-packages/enaml/core/pattern.py:33(initialize) 05-17 14:46:30.351 cython I/pybridge: 407/406 0.112 0.000 0.250 0.001 ./site-packages/atom/atom.py:182(new) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.245 0.245 /data/user/0/com.codelv.enamlnative.demo2/cache/view.enaml:249(ContentView) 05-17 14:46:30.351 cython I/pybridge: 424 0.007 0.000 0.245 0.001 ./site-packages/enaml/core/compiler_helpers.py:551(run_operator) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.237 0.237 ./site-packages/enamlnative/android/app.py:71(init) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.237 0.237 ./site-packages/enamlnative/core/app.py:125(init) 05-17 14:46:30.351 cython I/pybridge: 92/3 0.005 0.000 0.207 0.069 ./site-packages/enaml/widgets/toolkit_object.py:201(activate_proxy) 05-17 14:46:30.351 cython I/pybridge: 38 0.000 0.000 0.204 0.005 ./re.py:192(compile) 05-17 14:46:30.351 cython I/pybridge: 38 0.003 0.000 0.203 0.005 ./re.py:230(_compile) 05-17 14:46:30.351 cython I/pybridge: 38 0.001 0.000 0.199 0.005 ./sre_compile.py:567(compile) 05-17 14:46:30.351 cython I/pybridge: 1 0.000 0.000 0.192 0.192 ./site-packages/enaml/core/parser/base_parser.py:206(init) 05-17 14:46:30.351 cython I/pybridge: 625 0.008 0.000 0.181 0.000 ./site-packages/enaml/application.py:351(create_proxy) 05-17 14:46:30.351 cython I/pybridge: 1 0.001 0.001 0.173 0.173 ./site-packages/enamlnative/core/app.py:485(load_plugin_widgets) 05-17 14:46:30.351 cython I/pybridge: 1 0.017 0.017 0.172 0.172 ./site-packages/enamlnative/widgets/api.py:11() 05-17 14:46:30.351 cython I/pybridge: 625 0.008 0.000 0.169 0.000 ./site-packages/enaml/application.py:325(resolve_proxy_class) 05-17 14:46:30.351 cython I/pybridge: 92 0.001 0.000 0.166 0.002 ./site-packages/enaml/widgets/toolkit_object.py:218(activate_top_down) 05-17 14:46:30.351 cython I/pybridge: 92 0.001 0.000 0.165 0.002 ./site-packages/enamlnative/android/android_toolkit_object.py:69(activate_top_down) 05-17 14:46:30.351 cython I/pybridge: 970 0.005 0.000 0.154 0.000 ./site-packages/enaml/application.py:127(resolve) 05-17 14:46:30.351 cython I/pybridge: 1 0.001 0.001 0.127 0.127 ./main.py:8(get_application) 05-17 14:46:30.351 cython I/pybridge: 429 0.125 0.000 0.125 0.000 {method 'to_code' of 'enaml.core.byteplay.byteplay2.Code' objects} 05-17 14:46:30.351 cython I/pybridge: 1 0.004 0.004 0.125 0.125 ./site-packages/enamlnative/android/app.py:10() 05-17 14:46:30.351 cython I/pybridge: 38 0.001 0.000 0.115 0.003 ./sre_parse.py:725(parse) 05-17 14:46:30.351 cython I/pybridge: 357 0.005 0.000 0.114 0.000 ./site-packages/enaml/core/operators.py:49(gen_simple) 05-17 14:46:30.351 cython I/pybridge: 1 0.011 0.011 0.114 0.114 ./site-packages/enaml/core/parser/base_parser.py:8() 05-17 14:46:30.352 cython I/pybridge: 218/38 0.006 0.000 0.113 0.003 ./sre_parse.py:336(_parse_sub) 05-17 14:46:30.352 cython I/pybridge: 117 0.007 0.000 0.112 0.001 ./site-packages/enaml/core/declarative_meta.py:111(new) 05-17 14:46:30.352 cython I/pybridge: 381/107 0.036 0.000 0.110 0.001 ./sre_parse.py:414(_parse) 05-17 14:46:30.352 cython I/pybridge: 61 0.004 0.000 0.105 0.002 ./site-packages/enamlnative/android/android_view.py:143(init_widget) 05-17 14:46:30.352 cython I/pybridge: 1 0.001 0.001 0.105 0.105 ./site-packages/enamlnative/core/api.py:11() 05-17 14:46:30.352 cython I/pybridge: 1 0.001 0.001 0.104 0.104 ./site-packages/ply/yacc.py:3216(yacc) 05-17 14:46:30.352 cython I/pybridge: 1 0.001 0.001 0.102 0.102 ./site-packages/enamlnative/android/http.py:11() 05-17 14:46:30.352 cython I/pybridge: 326 0.005 0.000 0.097 0.000 ./site-packages/enaml/core/operators.py:127(op_simple) 05-17 14:46:30.352 cython I/pybridge: 1 0.004 0.004 0.096 0.096 ./site-packages/ply/yacc.py:62() 05-17 14:46:30.352 cython I/pybridge: 36 0.002 0.000 0.093 0.003 ./site-packages/enamlnative/android/android_button.py:82(init_widget) 05-17 14:46:30.352 cython I/pybridge: 1 0.001 0.001 0.093 0.093 ./site-packages/enamlnative/core/http.py:10() 05-17 14:46:30.352 cython I/pybridge: 639/142 0.007 0.000 0.092 0.001 ./site-packages/enaml/core/compiler_nodes.py:154(call) 05-17 14:46:30.352 cython I/pybridge: 1 0.001 0.001 0.091 0.091 ./inspect.py:25() 05-17 14:46:30.352 cython I/pybridge: 44 0.001 0.000 0.090 0.002 ./site-packages/enamlnative/android/android_text_view.py:144(init_widget) 05-17 14:46:30.352 cython I/pybridge: 981/141 0.020 0.000 0.089 0.001 ./site-packages/enaml/core/compiler_nodes.py:177(populate) 05-17 14:46:30.352 cython I/pybridge: 1 0.000 0.000 0.088 0.088 ./site-packages/enaml/core/parser/base_lexer.py:498(init) 05-17 14:46:30.352 cython I/pybridge: 1 0.000 0.000 0.087 0.087 ./site-packages/ply/lex.py:862(lex) 05-17 14:46:30.352 cython I/pybridge: 1 0.005 0.005 0.084 0.084 ./httplib.py:67() 05-17 14:46:30.352 cython I/pybridge: 65 0.001 0.000 0.084 0.001 ./site-packages/enaml/core/operators.py:185(op_subscribe) 05-17 14:46:30.352 cython I/pybridge: 1 0.000 0.000 0.083 0.083 ./site-packages/ply/lex.py:211(readtab) 05-17 14:46:30.352 cython I/pybridge: 38 0.000 0.000 0.083 0.002 ./sre_compile.py:552(_code) 05-17 14:46:30.352 cython I/pybridge: 65 0.002 0.000 0.083 0.001 ./site-packages/enaml/core/operators.py:73(gen_tracer) 05-17 14:46:30.352 cython I/pybridge: 1 0.001 0.001 0.073 0.073 ./tokenize.py:23() 05-17 14:46:30.352 cython I/pybridge: 380 0.014 0.000 0.070 0.000 ./site-packages/enamlnative/core/bridge.py:170(call) 05-17 14:46:30.352 cython I/pybridge: 1747/1746 0.068 0.000 0.070 0.000 {built-in method new of type object at 0x8db589c4} 05-17 14:46:30.352 cython I/pybridge: 20 0.001 0.000 0.070 0.003 {map}

Any ideas on what else could be optimized?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codelv/enaml-native/issues/59#issuecomment-389974877, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIYSeoYJPOhi6bMPFllaSjJRQUI-BZ3ks5tzcpggaJpZM4R8ACc .

frmdstryr commented 6 years ago

The profile stats above are from the second app start. The first start is slower as it must extract the python stdlib and site-packages (pre compiled to .pyc) to the phone and I can see that the enamlc file exists on the device so they must be generated on the first start as well.

lv517:/data/data/com.codelv.enamlnative.demo1/cache $ find | grep enamlc
./__enamlcache__
./__enamlcache__/view.enaml-py27-cv26.enamlc

Currently pre compiled enamlc files are not bundled with the app but this is something I want to add.

Is there something like the compileall command for enaml files (other than just importing them)?

sccolbert commented 6 years ago

There's no equivalent to compileall. Wouldn't be too hard to implement though.

On Thu, May 17, 2018 at 3:47 PM, frmdstryr notifications@github.com wrote:

The profile stats above are from the second app start. The first start is slower as it must extract the python stdlib and site-packages (pre compiled to .pyc) to the phone and I can see that the enamlc file exists on the device so they must be generated on the first start as well.

lv517:/data/data/com.codelv.enamlnative.demo1/cache $ find | grep enamlc ./enamlcache ./enamlcache/view.enaml-py27-cv26.enamlc

Currently pre compiled enamlc files are not bundled with the app but this is something I want to add.

Is there something like the compileall https://docs.python.org/2/library/compileall.html#module-compileall command for enaml files (other than just importing them)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codelv/enaml-native/issues/59#issuecomment-390006182, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIYSX1beSnF_QGZck8vmj13ukQql_Fcks5tzeHqgaJpZM4R8ACc .

sccolbert commented 6 years ago

You might want to set a breakpoint in the enaml importer to make sure its using the precompiled .enamlc file. I could have sworn byteplay wasn't involved when loading from cache, but it's possible I'm mistaken. However, it looks like the parser is being invoked in the stack trace, which makes me think the cached file is not being used.

On Thu, May 17, 2018 at 4:46 PM, Chris Colbert sccolbert@gmail.com wrote:

There's no equivalent to compileall. Wouldn't be too hard to implement though.

On Thu, May 17, 2018 at 3:47 PM, frmdstryr notifications@github.com wrote:

The profile stats above are from the second app start. The first start is slower as it must extract the python stdlib and site-packages (pre compiled to .pyc) to the phone and I can see that the enamlc file exists on the device so they must be generated on the first start as well.

lv517:/data/data/com.codelv.enamlnative.demo1/cache $ find | grep enamlc ./enamlcache ./enamlcache/view.enaml-py27-cv26.enamlc

Currently pre compiled enamlc files are not bundled with the app but this is something I want to add.

Is there something like the compileall https://docs.python.org/2/library/compileall.html#module-compileall command for enaml files (other than just importing them)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codelv/enaml-native/issues/59#issuecomment-390006182, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIYSX1beSnF_QGZck8vmj13ukQql_Fcks5tzeHqgaJpZM4R8ACc .

MatthieuDartiailh commented 6 years ago

Looking at the called function, it seems to me that the cached files are not properly loaded since otherwise you would not see any call to the parser. (Sorry @sccolbert I made a typo) As for pre compiling, I did some experiments in my own fork (around the 0.10.3dev tag) but I abandonned when I realized that using setuptools extension was likely to cause issues (because packages listed both in setup_requires and install_requires are not actually installed). But I had to add the manual compilation logic.

sccolbert commented 6 years ago

If the cache files are not being loaded, you would definitely see calls to the parser. Not the other way around.

On Thu, May 17, 2018 at 4:51 PM, Matthieu Dartiailh < notifications@github.com> wrote:

Looking at the called function, it seems to me that the cached files are properly loaded since otherwise you would not see any call to the parser. As for pre compiling, I did some experiments in my own fork (around the 0.10.3dev tag) but I abandonned when I realized that using setuptools extension was likely to cause issues (because packages listed both in setup_requires and install_requires are not actually installed). But I had to add the manual compilation logic.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codelv/enaml-native/issues/59#issuecomment-390024871, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIYSfachIlgnhIVuMclhMNCRKShZPleks5tzfDegaJpZM4R8ACc .

MatthieuDartiailh commented 6 years ago

@frmdstryr did you figure out why the cache is not used ?