pcdshub / btms-ui

Laser Hall Beam Transport Motion System User Interface
Other
0 stars 4 forks source link

Improve BTMS GUI Launch Speed #22

Open slactjohnson opened 1 week ago

slactjohnson commented 1 week ago

Expected Behavior

The BTMS UI should open up in a reasonable amount of time, e.g. a few seconds, when launching the GUI.

Current Behavior

The screen currently takes about 13 seconds to open.

Possible Solution

I suspect that at least some of this overhead has to do with the way it's using the happi database and loading typhos screens. There may be ways to lazy-load things to reduce startup time. A splash screen that let's the user know it's loading could also help.

Context

This is long enough that it has made some people press the button several times, or think that the screen is not working.

tangkong commented 1 week ago

A very very quick profiling session because I got nerd sniped. Disregard the actual numbers here and just look at them relative to each other

`python -m cProfile -s 'cumtime' -m btms_ui.main`

```bash libGL error: No matching fbConfigs or visuals found libGL error: failed to load driver: swrast /cds/group/pcds/pyps/conda/py39/envs/pcds-5.9.0/lib/python3.9/site-packages/epics/ca.py:1631: UserWarning: ca.get('LTLHN:LD1:LS1:BTPS:Linear:Nominal_RBV') timed out after 5.00 seconds. warnings.warn(msg % (name(chid), timeout)) /cds/group/pcds/pyps/conda/py39/envs/pcds-5.9.0/lib/python3.9/site-packages/epics/ca.py:1631: UserWarning: ca.get('LTLHN:LS1:BTPS:CurrentLD_RBV') timed out after 5.00 seconds. warnings.warn(msg % (name(chid), timeout)) /cds/group/pcds/pyps/conda/py39/envs/pcds-5.9.0/lib/python3.9/site-packages/epics/ca.py:1631: UserWarning: ca.get('LTLHN:BTPS:Config:MinPixelChange') timed out after 5.00 seconds. warnings.warn(msg % (name(chid), timeout)) 7993568 function calls (7747470 primitive calls) in 56.666 seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 2 0.000 0.000 56.915 28.458 main.py:1() 2940/1 0.068 0.000 56.858 56.858 {built-in method builtins.exec} 1 0.000 0.000 56.857 56.857 :1() 1 0.000 0.000 56.857 56.857 runpy.py:200(run_module) 1 0.000 0.000 56.831 56.831 runpy.py:64(_run_code) 1 2.376 2.376 47.864 47.864 main.py:67(main) 273 0.012 0.000 34.095 0.125 __init__.py:1() 1 20.614 20.614 22.789 22.789 {built-in method exec_} 1 0.000 0.000 15.269 15.269 widgets.py:1458(prefix) 1 0.000 0.000 13.538 13.538 widgets.py:1344(prefix) 1 0.000 0.000 13.538 13.538 scene.py:986(device_prefix) 1 0.000 0.000 13.538 13.538 scene.py:1000(_create_device) 106824/66117 0.112 0.000 12.150 0.000 ca.py:591(wrapper) 2866/15 0.016 0.000 11.190 0.746 :1002(_find_and_load) 2820/13 0.015 0.000 11.190 0.861 :967(_find_and_load_unlocked) 2391/18 0.008 0.000 11.183 0.621 :844(exec_module) 2543/16 0.017 0.000 11.178 0.699 :659(_load_unlocked) 3290/20 0.003 0.000 11.158 0.558 :220(_call_with_frames_removed) 3269/1885 0.011 0.000 11.041 0.006 pv.py:34(wrapped) 26553 0.051 0.000 10.105 0.000 ca.py:1024(poll) 1 0.002 0.002 10.025 10.025 scene.py:425(device) 132 0.000 0.000 9.486 0.072 signal.py:1211(subscribe) ```

Zach's the profiling master around here, but I think we can ignore the runpy.py and main.py calls since those will be run for as long as I had the ui open. The next culprits are the widget building and device loading. Note that there were a few CA timeouts that we might be waiting on serially here as well.

slactjohnson commented 1 week ago

Thanks Robert! I'll take a closer look when I can.

ZLLentz commented 1 week ago

it's a bit strange that the prefix setters here are taking so much time, but maybe there's a lot of work to do after setting the PV