Skip to content

Commit 6261017

Browse files
committed
Disable Clang optimizations for Session::get*LibraryCode() functions
Clang was taking around 10 minutes to compile `slang-embedded-core-module-source.cpp` with optimizations. Disabling optimizations for these functions reduced the compilation time to about 12 seconds on my machine (Intel Core Ultra 7 165H), and had no noticeable impact on run-time performance. Run-time performance with optimizations: ``` $ hyperfine --shell=none './build/generators/Release/bin/slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source slang-core-module-generated.h -save-glsl-module-bin-source slang-glsl-module-generated.h' Benchmark 1: ./build/generators/Release/bin/slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source slang-core-module-generated.h -save-glsl-module-bin-source slang-glsl-module-generated.h Time (mean ± σ): 2.545 s ± 0.035 s [User: 2.333 s, System: 0.210 s] Range (min … max): 2.496 s … 2.620 s 10 runs ``` Run-time performance without optimizations: ``` $ hyperfine --shell=none './build/generators/Release/bin/slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source slang-core-module-generated.h -save-glsl-module-bin-source slang-glsl-module-generated.h' Benchmark 1: ./build/generators/Release/bin/slang-bootstrap -archive-type riff-lz4 -save-core-module-bin-source slang-core-module-generated.h -save-glsl-module-bin-source slang-glsl-module-generated.h Time (mean ± σ): 2.564 s ± 0.039 s [User: 2.350 s, System: 0.213 s] Range (min … max): 2.512 s … 2.614 s 10 runs ``` Disabling optimizations also makes `slang-embedded-core-module-source.cpp.o` slightly smaller: - 7.84 MiB with optimizations, - 7.37 MiB without optimizations. Fixes #9054.
1 parent 1152af7 commit 6261017

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source/slang-core-module/slang-embedded-core-module-source.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,13 @@ struct IntrinsicOpInfo
326326

327327
#define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__ + 1) << " \"" << path << "\"\n"
328328

329+
#if SLANG_CLANG
330+
// Clang takes around 10 minutes to compile this file with optimizations, with EarlyCSEPass taking
331+
// ~95% of the execution time. Disabling optimizations here reduces the compilation time to seconds
332+
// and has no noticeable impact on run-time performance.
333+
#pragma clang optimize off
334+
#endif
335+
329336
ComPtr<ISlangBlob> Session::getCoreLibraryCode()
330337
{
331338
#if SLANG_EMBED_CORE_MODULE_SOURCE
@@ -382,3 +389,7 @@ ComPtr<ISlangBlob> Session::getGLSLLibraryCode()
382389
return glslLibraryCode;
383390
}
384391
} // namespace Slang
392+
393+
#if SLANG_CLANG
394+
#pragma clang optimize on
395+
#endif

0 commit comments

Comments
 (0)