Skip to content

Commit 9acc2e1

Browse files
authored
Merge pull request #3343 from reframe-hpc/bugfix/optimize-json-decoding
[enhancement] Optimize JSON decoding for sessions when applying filtering criteria
2 parents 7dee9e7 + db4cb44 commit 9acc2e1

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

reframe/frontend/reporting/storage.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,41 @@ 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(
247+
f'decoding JSON raw data of length {len(data)}'
248+
)
249+
return json.loads(data)
250+
251+
session_infos = {}
236252
sessions = {}
237253
for uuid, json_blob in results:
238254
sessions.setdefault(uuid, json_blob)
255+
session_infos.setdefault(uuid, _extract_sess_info(json_blob))
239256

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:
257+
# Find the UUIDs to decode fully by inspecting only the session info
258+
uuids = []
259+
for sess_info in _mass_json_decode(session_infos.values()):
249260
try:
250-
if self._db_filter_json(sess_filter, rpt['session_info']):
251-
sessions[rpt['session_info']['uuid']] = rpt
261+
if self._db_filter_json(sess_filter, sess_info):
262+
uuids.append(sess_info['uuid'])
252263
except Exception:
253264
continue
254265

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

257272
@time_function
258273
def _fetch_testcases_raw(self, condition):

0 commit comments

Comments
 (0)