Skip to content

Commit 4f27337

Browse files
committed
Only check the savings if a word occurs at least twice
Profiling shows that `est_net_savings` is one of the highest costs of the whole process. Approximately, you can save storage only if a word appears more than once, and doing this greatly reduces the number of `est_net_savings` calls. Locally, it reduces the time for this specific build step by 50% on ports/unix coverage build, without affecting the size of the generated binary.
1 parent 3ff7ed7 commit 4f27337

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

py/makeqstrdata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ def est_net_savings(s, occ):
400400
# words[] array.
401401

402402
scores = sorted(
403-
((s, -est_net_savings(s, occ)) for (s, occ) in counter.items()), key=lambda x: x[1]
403+
((s, -est_net_savings(s, occ)) for (s, occ) in counter.items() if occ > 1),
404+
key=lambda x: x[1],
404405
)
405406

406407
# Pick the one with the highest score. The score must be negative.

0 commit comments

Comments
 (0)