Skip to content

Commit 58730e1

Browse files
committed
Optimize JSON decoding for sessions when using filters
1 parent 3637536 commit 58730e1

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

reframe/frontend/reporting/storage.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,39 @@ def _decode_sessions(self, results, sess_filter):
233233
234234
Return a map of session uuids to decoded session data
235235
'''
236+
sess_info_patt = re.compile(
237+
r'\"session_info\":\s+(?P<sess_info>\{.*?\})'
238+
)
239+
240+
def _extract_sess_info(s):
241+
return sess_info_patt.search(s).group('sess_info')
242+
243+
@time_function
244+
def _mass_json_decode(json_objs):
245+
data = '[' + ','.join(json_objs) + ']'
246+
getlogger().debug(f'decoding {len(data)} bytes')
247+
return json.loads(data)
248+
249+
session_infos = {}
236250
sessions = {}
237251
for uuid, json_blob in results:
238252
sessions.setdefault(uuid, json_blob)
253+
session_infos.setdefault(uuid, _extract_sess_info(json_blob))
239254

240-
# Join all sessions and decode them at once
241-
reports_blob = '[' + ','.join(sessions.values()) + ']'
242-
getprofiler().enter_region('json decode')
243-
reports = json.loads(reports_blob)
244-
getprofiler().exit_region()
245-
246-
# Reindex and filter sessions based on their decoded data
247-
sessions.clear()
248-
for rpt in reports:
255+
# Find the UUIDs to decode fully by inspecting only the session info
256+
uuids = []
257+
for info in _mass_json_decode(session_infos.values()):
249258
try:
250-
if self._db_filter_json(sess_filter, rpt['session_info']):
251-
sessions[rpt['session_info']['uuid']] = rpt
259+
if self._db_filter_json(sess_filter, info):
260+
uuids.append(info['uuid'])
252261
except Exception:
253262
continue
254263

255-
return sessions
264+
# Decode selected sessions
265+
reports = _mass_json_decode(sessions[uuid] for uuid in uuids)
266+
267+
# Return only the selected sessions
268+
return {rpt['session_info']['uuid']: rpt for rpt in reports}
256269

257270
@time_function
258271
def _fetch_testcases_raw(self, condition):

0 commit comments

Comments
 (0)