From 28758e0e427ceca196937dc90efe3ab1cb35bd70 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 17 Jul 2025 14:59:33 +0800 Subject: Perf improvements to IR serialization (#7751) * option to use riff as serialization backend * option to use riff as serialization backend * perf * shuffle code * perf improvements to deserialization * formatting * remove bit_cast * correct IR verification * neaten serialized format * fix peek module info * formatting * remove temporary profiling code * cleanup * fix wasm build * more explicit sizes * deserialize via fossil on 32 bit wasm * Make serialized modules Int size agnostic * reorder stable names to allow range based check for 64 bit constants * format * review comments * fix build * fix * c++17 compat slang-common.h --- source/core/slang-common.h | 19 +++++++++++++++++-- source/core/slang-performance-profiler.cpp | 21 ++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'source/core') diff --git a/source/core/slang-common.h b/source/core/slang-common.h index 9248e250f..015c3233c 100644 --- a/source/core/slang-common.h +++ b/source/core/slang-common.h @@ -5,7 +5,9 @@ #include #include +#include #include +#include #define VARIADIC_TEMPLATE @@ -199,6 +201,19 @@ inline bool isBitSet(T value, T bitToTest) static_assert(sizeof(T) <= sizeof(uint32_t), "Only support up to 32 bit enums"); return (T)((uint32_t)value & (uint32_t)bitToTest) == bitToTest; } + +template +typename std::enable_if_t< + sizeof(To) == sizeof(From) && std::is_trivially_copyable_v && + std::is_trivially_copyable_v && std::is_trivially_constructible_v, + To> +bitCast(const From& src) +{ + To dst; + std::memcpy(&dst, &src, sizeof(To)); + return dst; +} + } // namespace Slang // SLANG_DEFER @@ -349,7 +364,7 @@ public: #define SLANG_ASSERT(VALUE) \ do \ { \ - if (!(VALUE)) \ + if (!(VALUE)) [[unlikely]] \ SLANG_ASSERT_FAILURE(#VALUE); \ } while (0) #else @@ -357,7 +372,7 @@ public: #endif #define SLANG_RELEASE_ASSERT(VALUE) \ - if (VALUE) \ + if (VALUE) [[likely]] \ { \ } \ else \ diff --git a/source/core/slang-performance-profiler.cpp b/source/core/slang-performance-profiler.cpp index 9bc532680..bd046f4cc 100644 --- a/source/core/slang-performance-profiler.cpp +++ b/source/core/slang-performance-profiler.cpp @@ -35,15 +35,22 @@ public: char buffer[512]; for (const auto& func : data) { - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "[*] %30s", func.key); - out << buffer << " \t"; - auto milliseconds = - std::chrono::duration_cast(func.value.duration); - out << func.value.invocationCount << " \t" - << static_cast(milliseconds.count()) << "ms\n"; + auto microseconds = + std::chrono::duration_cast(func.value.duration); + double milliseconds = microseconds.count() / 1000.0; + snprintf( + buffer, + sizeof(buffer), + "[*] %30s \t%d \t%8.2fms\n", + func.key, + func.value.invocationCount, + milliseconds); + + out << buffer; } } + + virtual void clear() override { data.clear(); } virtual void dispose() override { data = decltype(data)(); } }; -- cgit v1.2.3