Skip to content

Commit 4b42740

Browse files
performance testing
1 parent bcdf8f9 commit 4b42740

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

app_pages/Unity_vs_CR.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import time
22
start = time.time()
33
import streamlit as st
4+
st.write("Streamlit import", time.time() - start)
5+
start = time.time()
46
from settings import initialize
7+
st.write("Settings import", time.time() - start)
8+
start = time.time()
59
from ui_components import create_funnels
10+
st.write("UI Components", time.time() - start)
11+
start = time.time()
612
import ui_widgets as ui
7-
import users
8-
from metrics import get_user_cohort_list
13+
st.write("UI Widgets", time.time() - start)
914

10-
st.write("Imports done", time.time() - start)
1115
initialize()
1216

1317
ui.display_definitions_table("Data Notes",ui.data_notes)
14-
countries_list = users.get_country_list()
18+
19+
@st.cache_data
20+
def load_countries():
21+
from users import get_country_list
22+
return get_country_list()
23+
24+
countries_list = load_countries()
1525

1626
ui.colorize_multiselect_options()
1727

@@ -24,7 +34,13 @@
2434
daterange = ui.convert_date_to_range(selected_date, option)
2535

2636
with col_lang:
27-
languages = users.get_language_list()
37+
@st.cache_data
38+
def load_languages():
39+
from users import get_language_list
40+
return get_language_list()
41+
42+
languages = load_languages()
43+
2844
language = ui.single_selector(
2945
languages, placement="middle", title="Select a language", key="acq-1"
3046
)
@@ -53,14 +69,25 @@
5369

5470
if len(daterange) == 2 and countries_list:
5571

72+
#delayed loading of import
73+
@st.cache_data(show_spinner="Loading user cohorts…")
74+
def get_user_cohort_list_lazy(daterange, languages, countries_list, app):
75+
from metrics import get_user_cohort_list
76+
return get_user_cohort_list(
77+
daterange=daterange,
78+
languages=languages,
79+
countries_list=countries_list,
80+
app=app
81+
)
82+
5683
# --- Get user cohorts ---
57-
user_cohort_list_unity = get_user_cohort_list(
84+
user_cohort_list_unity = get_user_cohort_list_lazy(
5885
daterange=daterange,
5986
languages=language,
6087
countries_list=countries_list,
6188
app="Unity"
6289
)
63-
user_cohort_list_cr = get_user_cohort_list(
90+
user_cohort_list_cr = get_user_cohort_list_lazy(
6491
daterange=daterange,
6592
languages=language,
6693
countries_list=countries_list,

0 commit comments

Comments
 (0)