Skip to content

Commit 15ab062

Browse files
authored
Improve performance (#26)
* set debug false * black * only disable specific debug option * add note about performance
1 parent 7dca3fc commit 15ab062

10 files changed

+39
-21
lines changed

dash_slicer/slicer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class VolumeSlicer:
5050
5151
The value in the store must be an 3-element tuple (x, y, z) in scene coordinates.
5252
To apply the position for one position only, use e.g ``(None, None, x)``.
53+
54+
Some notes on performance: for a smooth experience, create the `Dash`
55+
application with `update_title=None`, and when running the server in debug
56+
mode, consider setting `dev_tools_props_check=False`.
5357
"""
5458

5559
_global_slicer_counter = 0

examples/bring_your_own_slider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ def handle_dropdown_input(index):
5151

5252

5353
if __name__ == "__main__":
54-
app.run_server(debug=True)
54+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
55+
app.run_server(debug=True, dev_tools_props_check=False)

examples/slicer_customized.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ def handle_button_input(press1, press2, index):
7676

7777

7878
if __name__ == "__main__":
79-
app.run_server(debug=True)
79+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
80+
app.run_server(debug=True, dev_tools_props_check=False)

examples/slicer_with_1_plus_2_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@
7474

7575

7676
if __name__ == "__main__":
77-
app.run_server(debug=True)
77+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
78+
app.run_server(debug=True, dev_tools_props_check=False)

examples/slicer_with_1_view.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import imageio
99

1010

11-
app = dash.Dash(__name__)
11+
app = dash.Dash(__name__, update_title=None)
1212

1313
vol = imageio.volread("imageio:stent.npz")
1414
slicer = VolumeSlicer(app, vol)
@@ -17,4 +17,5 @@
1717

1818

1919
if __name__ == "__main__":
20-
app.run_server(debug=True)
20+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
21+
app.run_server(debug=True, dev_tools_props_check=False)

examples/slicer_with_2_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@
4343

4444

4545
if __name__ == "__main__":
46-
app.run_server(debug=True)
46+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
47+
app.run_server(debug=True, dev_tools_props_check=False)

examples/slicer_with_3_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@
6969

7070

7171
if __name__ == "__main__":
72-
app.run_server(debug=True)
72+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
73+
app.run_server(debug=True, dev_tools_props_check=False)

examples/threshold_overlay.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ def apply_levels(level):
6262

6363

6464
if __name__ == "__main__":
65-
app.run_server(debug=True)
65+
# Note: dev_tools_props_check negatively affects the performance of VolumeSlicer
66+
app.run_server(debug=True, dev_tools_props_check=False)

tests/performance1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@
146146

147147

148148
if __name__ == "__main__":
149-
app.run_server(debug=True)
149+
# Note that the dev_tools_props_check negatively affects performance
150+
app.run_server(debug=True, dev_tools_props_check=False)

tests/peformance2.py renamed to tests/performance2.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
html.Br(),
5353
dcc.Graph(id="graph", figure=fig),
5454
dcc.Store(id="index", data=0),
55+
dcc.Store(id="trace", data=None),
5556
dcc.Store(id="data_png", data=slices_png),
5657
]
5758
)
@@ -72,7 +73,19 @@
7273

7374
app.clientside_callback(
7475
"""
75-
function update_figure(index, ori_figure, data_png) {
76+
function update_trace(index, data_png) {
77+
return {type: 'image', source: data_png[index]};
78+
}
79+
""",
80+
Output("trace", "data"),
81+
[Input("index", "data")],
82+
[State("data_png", "data")],
83+
)
84+
85+
86+
app.clientside_callback(
87+
"""
88+
function update_figure(trace, ori_figure) {
7689
7790
// Get FPS
7891
let fps_result = dash_clientside.no_update;
@@ -91,13 +104,11 @@
91104
let figure_result = dash_clientside.no_update;
92105
93106
if (true) {
94-
let trace = {type: 'image', source: data_png[index]};
95107
figure_result = {...ori_figure};
96108
figure_result.layout.yaxis.range = [128, 0];
97109
figure_result.data = [trace];
98110
} else {
99111
// unfavorable y-axis
100-
let trace = {type: 'image', source: data_png[index]};
101112
figure_result = {...ori_figure};
102113
figure_result.layout.yaxis.range = [0, 128];
103114
figure_result.data = [trace];
@@ -106,16 +117,11 @@
106117
}
107118
""",
108119
[Output("graph", "figure"), Output("fps", "children")],
109-
[
110-
# Input("index", "data")],
111-
Input("slider", "value")
112-
],
113-
[
114-
State("graph", "figure"),
115-
State("data_png", "data"),
116-
],
120+
[Input("trace", "data")],
121+
[State("graph", "figure")],
117122
)
118123

119124

120125
if __name__ == "__main__":
121-
app.run_server(debug=True)
126+
# Note that the dev_tools_props_check negatively affects performance
127+
app.run_server(debug=True, dev_tools_props_check=False)

0 commit comments

Comments
 (0)