From a3372605363cfe511b5248cb1393f59b25cb2483 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Thu, 9 Oct 2025 19:22:22 -0700 Subject: Improve perf with `-separate-debug-info` (#8670) When Slang form a new spirv code without the debug info, List container had to reserve the memory space before adding items in it. This improves the given repro test time from 56 minutes to 6 minutes. --- source/slang/slang-emit.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index c57851bc2..1bd1f8b5c 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -2342,6 +2342,10 @@ public: // we can read. SlangResult loadBlob(ComPtr& artifact) { + m_nonSemanticDebugInfoExtSetId = 0; + m_words.clear(); + m_headerWords.clear(); + ComPtr spirvBlob; SlangResult res = artifact->loadBlob(ArtifactKeep::Yes, spirvBlob.writeRef()); if (SLANG_FAILED(res) || !spirvBlob || @@ -2349,7 +2353,6 @@ public: return SLANG_FAIL; // Populate the full array of SPIR-V words. - m_words.clear(); m_words.addRange( reinterpret_cast(spirvBlob->getBufferPointer()), spirvBlob->getBufferSize() / sizeof(SpvWord)); @@ -2363,7 +2366,9 @@ public: } // Get the header words. - List getHeaderWords() const { return m_headerWords; } + const List& getHeaderWords() const { return m_headerWords; } + + Index getWordCount() const { return m_words.getCount(); } // Visit all SPIRV instructions (excluding header words), invoking the callback for each // instruction. The callback should be a function or lambda with signature: void(const @@ -2457,9 +2462,15 @@ static SlangResult stripDbgSpirvFromArtifact( SpirvInstructionHelper spirvInstructionHelper; SLANG_RETURN_ON_FAIL(spirvInstructionHelper.loadBlob(artifact)); - auto headerWords = spirvInstructionHelper.getHeaderWords(); + const auto& headerWords = spirvInstructionHelper.getHeaderWords(); List spirvWordsList; + if (auto totalWordCapacity = headerWords.getCount() + spirvInstructionHelper.getWordCount()) + { + const Index byteCapacity = totalWordCapacity * sizeof(SpvWord); + spirvWordsList.reserve(byteCapacity); + } + spirvWordsList.addRange( reinterpret_cast(headerWords.getBuffer()), headerWords.getCount() * sizeof(SpvWord)); -- cgit v1.2.3