Internals: Optimize temporary memory allocations (#6517)

This patch gets rid of over 80% of temporary dynamic memory allocations
(when a malloced node is immediately freed with no other malloc in
between). It also gets rid of over 20% of all calls to malloc.

It's worth ~3% average verilation speed up with tcmalloc, and more
without tcmalloc.
This commit is contained in:
Geza Lore
2025-10-01 15:01:30 +01:00
committed by GitHub
parent 435e1149d5
commit e9c48cd1ce
19 changed files with 218 additions and 216 deletions
+1 -6
View File
@@ -160,12 +160,7 @@ class StatsReport final {
public:
// METHODS
static void addStat(const V3Statistic& stat) {
// Avoid memory blow-up when called frequently with zero adds,
// e.g. from V3Const invoked on individual expressions.
if (stat.sumit() && stat.value() == 0.0) return;
s_allStats.push_back(stat);
}
static void addStat(const V3Statistic& stat) { s_allStats.push_back(stat); }
static double getStatSum(const string& name) {
// O(n^2) if called a lot; present assumption is only a small call count