Skip to content

Commit 278a5e4

Browse files
Performance fix for PyYAML comments (#513)
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]>
1 parent 32f3955 commit 278a5e4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

riscv-isac/riscv_isac/cgf_normalize.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,10 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
580580
if len(cgf[labels]['mnemonics'].keys()) > 1:
581581
logger.error(f'Multiple instruction mnemonics found when base_op label defined in {labels} label.')
582582

583-
# Substitute instruction aliases with equivalent tuple of instructions
583+
# Substitute instruction aliases with equivalent tuple of instructions
584584
if 'cross_comb' in cats:
585585
temp = cats['cross_comb']
586-
586+
587587
for covp, covge in dict(temp).items():
588588
data = covp.split('::')
589589
ops = data[0].replace(' ', '')[1:-1].split(':')
@@ -592,14 +592,14 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
592592
exp_alias = utils.import_instr_alias(ops[i])
593593
if exp_alias != None:
594594
ops[i] = tuple(exp_alias).__str__().replace("'", '').replace(" ", '')
595-
595+
596596
data[0] = '[' + ':'.join(ops) + ']'
597597
data = '::'.join(data)
598598
del temp[covp]
599599
temp[data] = covge
600-
601-
cgf[labels].insert(1, 'cross_comb', temp)
602-
600+
601+
cgf[labels].insert(1, 'cross_comb', temp)
602+
603603
l = len(cats.items())
604604
i = 0
605605
for label,node in cats.items():
@@ -618,7 +618,13 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False):
618618
for cp,comment in exp_cp:
619619
if log_redundant and cp in cgf[labels][label]:
620620
logger.warn(f'Redundant coverpoint during normalization: {cp}')
621-
cgf[labels][label].insert(l+i,cp,coverage,comment=comment)
621+
622+
# PyYAML has catastrophic performance adding comments
623+
# so only do it for the first 100 entries.
624+
if i < 100:
625+
cgf[labels][label].yaml_add_eol_comment(comment, key=cp)
626+
else:
627+
cgf[labels][label][cp] = coverage
628+
622629
i += 1
623630
return dict(cgf)
624-

0 commit comments

Comments
 (0)