From 51ad07d1fbffd41c758eba172aa77ebba3204924 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 23 Feb 2025 10:31:05 -0800 Subject: Improve performance when compiling small shaders. (#6396) Improve performance when compiling small shaders. Avoid copying witness table entries that are not getting used during linking. Avoid copying auto-diff related decorations and derivative functions during linking, if the user modules doesn't use autodiff. Cache operator overload resolution results on global session, so each new Session doesn't need to repetitively run through overload resolution from scratch. --- source/core/slang-string.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source/core') diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 24b119383..3da0db6b9 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -790,6 +790,57 @@ public: UnownedStringSlice getUnownedSlice() const { return StringRepresentation::asSlice(m_buffer); } }; +class ImmutableHashedString +{ +public: + String slice; + HashCode64 hashCode; + ImmutableHashedString() + : hashCode(0) + { + } + ImmutableHashedString(const UnownedStringSlice& slice) + : slice(slice), hashCode(slice.getHashCode()) + { + } + ImmutableHashedString(const char* begin, const char* end) + : slice(begin, end), hashCode(slice.getHashCode()) + { + } + ImmutableHashedString(const char* begin, size_t len) + : slice(UnownedStringSlice(begin, len)), hashCode(slice.getHashCode()) + { + } + ImmutableHashedString(const char* begin) + : slice(begin), hashCode(slice.getHashCode()) + { + } + ImmutableHashedString(const String& str) + : slice(str), hashCode(str.getHashCode()) + { + } + ImmutableHashedString(String&& str) + : slice(_Move(str)), hashCode(str.getHashCode()) + { + } + ImmutableHashedString(const ImmutableHashedString& other) = default; + ImmutableHashedString& operator=(const ImmutableHashedString& other) = default; + bool operator==(const ImmutableHashedString& other) const + { + return hashCode == other.hashCode && slice == other.slice; + } + bool operator!=(const ImmutableHashedString& other) const + { + return hashCode != other.hashCode || slice != other.slice; + } + bool operator==(const UnownedStringSlice& other) const { return slice == other; } + bool operator!=(const UnownedStringSlice& other) const { return slice != other; } + bool operator==(const String& other) const { return slice == other.getUnownedSlice(); } + bool operator!=(const String& other) const { return slice != other.getUnownedSlice(); } + bool operator==(const char* other) const { return slice == UnownedStringSlice(other); } + HashCode64 getHashCode() const { return hashCode; } +}; + class SLANG_RT_API StringBuilder : public String { private: -- cgit v1.2.3