Skip to content

Commit

Permalink
Performance fix for PyYAML comments (#513)
Browse files Browse the repository at this point in the history
PyYAML has really really bad performance when adding comments, so I changed it to only add them for the first 100 entries. I also removed the l+i offset which doesn't make sense because the type is a dictionary.

Co-authored-by: Umer Shahid <[email protected]>
  • Loading branch information
Timmmm and UmerShahidengr authored Oct 17, 2024
1 parent 32f3955 commit 278a5e4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions riscv-isac/riscv_isac/cgf_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,10 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
if len(cgf[labels]['mnemonics'].keys()) > 1:
logger.error(f'Multiple instruction mnemonics found when base_op label defined in {labels} label.')

# Substitute instruction aliases with equivalent tuple of instructions
# Substitute instruction aliases with equivalent tuple of instructions
if 'cross_comb' in cats:
temp = cats['cross_comb']

for covp, covge in dict(temp).items():
data = covp.split('::')
ops = data[0].replace(' ', '')[1:-1].split(':')
Expand All @@ -592,14 +592,14 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
exp_alias = utils.import_instr_alias(ops[i])
if exp_alias != None:
ops[i] = tuple(exp_alias).__str__().replace("'", '').replace(" ", '')

data[0] = '[' + ':'.join(ops) + ']'
data = '::'.join(data)
del temp[covp]
temp[data] = covge
cgf[labels].insert(1, 'cross_comb', temp)

cgf[labels].insert(1, 'cross_comb', temp)

l = len(cats.items())
i = 0
for label,node in cats.items():
Expand All @@ -618,7 +618,13 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
for cp,comment in exp_cp:
if log_redundant and cp in cgf[labels][label]:
logger.warn(f'Redundant coverpoint during normalization: {cp}')
cgf[labels][label].insert(l+i,cp,coverage,comment=comment)

# PyYAML has catastrophic performance adding comments
# so only do it for the first 100 entries.
if i < 100:
cgf[labels][label].yaml_add_eol_comment(comment, key=cp)
else:
cgf[labels][label][cp] = coverage

i += 1
return dict(cgf)

0 comments on commit 278a5e4

Please sign in to comment.