Skip to content

Use set lookup for reserved shader identifiers - #3107

Merged
jstone-lucasfilm merged 1 commit into
AcademySoftwareFoundation:mainfrom
tdavidovicNV:perf/reserved-word-lookup
Oct 8, 2026
Merged

jstone-lucasfilm merged 1 commit into
AcademySoftwareFoundation:mainfrom
tdavidovicNV:perf/reserved-word-lookup

Conversation

@tdavidovicNV

@tdavidovicNV tdavidovicNV commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

While profiling shader generation, I noticed that Syntax::makeValidName searches _reservedWords with std::find, even though the container is a std::set<string>.

This switches to the set's find member, making the lookup logarithmic instead of linear. The membership check and generated identifiers are unchanged.

I measured this change alone with the existing shader-generation tests over Materials/TestSuite and Materials/Examples. Each active configuration traverses 195 documents; the full run makes 6,868 generation calls across GLSL, GLSL with layouts, Vulkan/WGSL, Slang, OSL, MDL and MSL. There is no rendering or downstream shader compilation, and the suite's normal exclusions and per-document implementation-cache clearing are unchanged.

On my Core Ultra 9 285K (Windows, MSVC 19.38, x64 Release /O2), the complete test run took 1.3% less time, measured as the median of eight paired reductions. That includes loading, document validation, code generation, assertions and normal test logging. Baseline/candidate order alternated, with both processes pinned to the same performance core after a full warmup each. All eight pairs improved, ranging from 0.1% to 7.5%; the initial unpinned measurements were too noisy to draw a conclusion. Separately timing just generation and source collection gave a 1.7% median paired reduction across all eight configurations. All 12,016 generated shader-stage sources were byte-identical, and the selected generation tests passed.

Assisted-by: OpenAI Codex

I used Codex to help with the implementation, profiling/benchmarks and this description.

@tdavidovicNV tdavidovicNV reopened this Oct 8, 2026

@jstone-lucasfilm jstone-lucasfilm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this improvement, @tdavidovicNV!

@jstone-lucasfilm
jstone-lucasfilm merged commit 310e1d4 into AcademySoftwareFoundation:main Oct 8, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants