Skip to content

Conversation

@ncelikNV
Copy link
Contributor

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.

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 shader-slang#9054.
@ncelikNV ncelikNV requested a review from a team as a code owner November 19, 2025 14:57
@ncelikNV ncelikNV added the pr: non-breaking PRs without breaking changes label Nov 19, 2025
@jkwak-work
Copy link
Collaborator

I think we still want to enable the optimization for the release package and anybody building Slang from source code.
This optimization should be applied to Slang dev members who compiles frequently.
And it should be gated by CMake build flag as described in the issue:

@ncelikNV
Copy link
Contributor Author

ncelikNV commented Nov 20, 2025

These functions are only called in the following cases:

  • By slang-bootstrap when building Slang.
  • By slangd at start-up if --print-builtin-module was passed as command-line argument.
  • At run time if -DSLANG_EMBED_CORE_MODULE=OFF was passed to CMake when building Slang. Do we know if any users disable this CMake option?

As I've shown, disabling optimizations for these functions has no noticeable impact on slang-bootstrap's execution time, and code size isn't lower with optimizations either.

Clang takes 11-15x as long as GCC to compile this file, and >90% of the compilation time is spent on one single LLVM optimization pass. There is something wrong with LLVM here. See llvm/llvm-project#132554.

Why make this more complex just so we can only optionally work around a bug in LLVM, when the workaround shows no downsides?

@jkwak-work
Copy link
Collaborator

I see the point.
This part of code doesn't really need to be optimized because it will run to generate the slang-XXX-module.bin only once.
Let's go with what we have here.

jkwak-work
jkwak-work previously approved these changes Nov 20, 2025
Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Let's go with this simpler approach rather than adding a new CMake option.

Copy link
Contributor

@jkiviluoto-nv jkiviluoto-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but stating the runtime impact in comment makes sense.

Copy link
Contributor

@jkiviluoto-nv jkiviluoto-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ncelikNV ncelikNV added this pull request to the merge queue Nov 24, 2025
Merged via the queue into shader-slang:master with commit 6316dad Nov 24, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

slang-embedded-core-module-source.cpp takes long to compile with Clang 18 & 20

3 participants