From 4cb3eeb832b5fb29a61f2934b3daa5e42a3d6cde Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 18 Jul 2023 08:08:11 -0700 Subject: Simplify Lookup and improve compiler performance. (#2996) * Simplify lookup. * Various bug fixes. * Report type dictionary size in perf benchmark. * Remove type duplication. * increase initial dict size. * Bug fix. * Fix bugs. * Fixup. * Revert type legalization looping. * Fix specialization pass. --------- Co-authored-by: Yong He --- source/core/core.natvis | 38 +++++++++++++++++++------------------- source/core/slang-dictionary.h | 36 ++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 33 deletions(-) (limited to 'source/core') diff --git a/source/core/core.natvis b/source/core/core.natvis index d9035e8ba..2448e2c88 100644 --- a/source/core/core.natvis +++ b/source/core/core.natvis @@ -55,33 +55,33 @@ - {{ size={_count} }} + {{ size={m_count} }} - _count - bucketSizeMinusOne + 1 + m_count + m_bucketCountMinusOne + 1 - + - _count - pBucket = hashMap + m_count + pBucket = m_hashMap - + - isDeleted = marks.m_buffer.m_count > (iBucket*2+1)/32 - ? ((marks.m_buffer.m_buffer[(iBucket*2+1)/32]&(1<<(iBucket*2+1)%32)) != 0) + isDeleted = m_marks.m_buffer.m_count > (iBucket*2+1)/32 + ? ((m_marks.m_buffer.m_buffer[(iBucket*2+1)/32]&(1<<(iBucket*2+1)%32)) != 0) : 0 - isEmpty = marks.m_buffer.m_count > (iBucket*2)/32 - ? ((marks.m_buffer.m_buffer[(iBucket*2)/32]&(1<<(iBucket*2)%32)) == 0) + isEmpty = m_marks.m_buffer.m_count > (iBucket*2)/32 + ? ((m_marks.m_buffer.m_buffer[(iBucket*2)/32]&(1<<(iBucket*2)%32)) == 0) : 1 - *(hashMap + iBucket) + *(m_hashMap + iBucket) iBucket++ @@ -93,21 +93,21 @@ {{ size={dict._count} }} - dict._count - dict.kvPairs.head + m_dict._count + m_dict.kvPairs.head next - Value + value - {{ size={_count} }} + {{ size={m_count} }} - _count - kvPairs.head + m_count + m_kvPairs.head next - Value + value diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h index 0350a99d2..2c683abfe 100644 --- a/source/core/slang-dictionary.h +++ b/source/core/slang-dictionary.h @@ -191,20 +191,9 @@ namespace Slang int newSize = (m_bucketCountMinusOne + 1) * 2; if (newSize == 0) { - newSize = 16; + newSize = 64; } - Dictionary newDict; - newDict.m_bucketCountMinusOne = newSize - 1; - newDict.m_hashMap = new KeyValuePair[newSize]; - newDict.m_marks.resizeAndClear(newSize * 2); - if (m_hashMap) - { - for (auto& kvPair : *this) - { - newDict.add(_Move(kvPair)); - } - } - *this = _Move(newDict); + reserve(newSize); } } @@ -344,6 +333,25 @@ namespace Slang m_marks.clear(); } + void reserve(int newSize) + { + if (newSize <= m_bucketCountMinusOne + 1) + return; + + Dictionary newDict; + newDict.m_bucketCountMinusOne = newSize - 1; + newDict.m_hashMap = new KeyValuePair[newSize]; + newDict.m_marks.resizeAndClear(newSize * 2); + if (m_hashMap) + { + for (auto& kvPair : *this) + { + newDict.add(_Move(kvPair)); + } + } + *this = _Move(newDict); + } + TValue* tryGetValueOrAdd(const TKey& key, const TValue& value) { maybeRehash(); @@ -785,7 +793,7 @@ namespace Slang int newSize = (m_bucketCountMinusOne + 1) * 2; if (newSize == 0) { - newSize = 16; + newSize = 128; } OrderedDictionary newDict; newDict.m_bucketCountMinusOne = newSize - 1; -- cgit v1.2.3