From 2c8b4d7ad13e4817a36b3c20f20a47b658dd5b9e Mon Sep 17 00:00:00 2001 From: Drew Lewis Date: Tue, 22 Jul 2025 19:49:10 +0000 Subject: [PATCH] Use unordered_map instead of dict for IdString char* to index storage. dict is pretty slow when you don't ever need to iterate the container in order. And the hashfunction for char* in dict hashes for every single byte in the string, likely doing significantly more work than std::hash. --- kernel/rtlil.cc | 2 +- kernel/rtlil.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 8a0080dbf..d24ab4d1e 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -35,7 +35,7 @@ YOSYS_NAMESPACE_BEGIN bool RTLIL::IdString::destruct_guard_ok = false; RTLIL::IdString::destruct_guard_t RTLIL::IdString::destruct_guard; std::vector RTLIL::IdString::global_id_storage_; -dict RTLIL::IdString::global_id_index_; +std::unordered_map RTLIL::IdString::global_id_index_; #ifndef YOSYS_NO_IDS_REFCNT std::vector RTLIL::IdString::global_refcount_storage_; std::vector RTLIL::IdString::global_free_idx_list_; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 504fa0062..745b8fcaf 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -23,6 +23,9 @@ #include "kernel/yosys_common.h" #include "kernel/yosys.h" +#include +#include + YOSYS_NAMESPACE_BEGIN namespace RTLIL @@ -122,7 +125,7 @@ struct RTLIL::IdString } destruct_guard; static std::vector global_id_storage_; - static dict global_id_index_; + static std::unordered_map global_id_index_; #ifndef YOSYS_NO_IDS_REFCNT static std::vector global_refcount_storage_; static std::vector global_free_idx_list_;