Repository navigation
Erase MilkdropShader's sampler and texsize declarations without scanning the whole shader each time - #1048
Open
Hyphen-05 wants to merge 1 commit into
Open
Erase MilkdropShader's sampler and texsize declarations without scanning the whole shader each time#1048Hyphen-05 wants to merge 1 commit into
Hyphen-05 wants to merge 1 commit into
Conversation
…ing the whole shader each time The regexes are built once when the library loads, and Utils::EraseRegexMatches() only tries them where their fixed first word occurs. The result is the same as the old regex_search() loops.
kblaschke
approved these changes
Oct 14, 2026
kblaschke
left a comment
Member
There was a problem hiding this comment.
LGTM
Thanks for the contribution!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MilkdropShader::TranspileHLSLShader()removes sampler and texsize declarations with twowhile (std::regex_search(...))loops. Each pass constructs the regex again and searches the whole shader from thestart. On a Moto G Play (2023), 32-bit ARM with libc++, the two loops take about 7.5 ms per shader, so 15 ms on every
preset load. That is part of the stutter on preset switches reported in #913.
The two regexes are now built once when the library loads. That alone makes no measurable difference, because
constructing them only takes about 25 µs. The time is spent in
regex_searchtrying the pattern at every position.Both patterns start with a fixed word, so the new
Utils::EraseRegexMatches()finds that word withstd::string::find()and only tries the regex there, usingmatch_continuous. After each erase it searches againfrom the start, like the old loop, because an erase can create a new match further up.
29 shaders from Cream of the Crop presets, per shader, on the same phone:
The output is identical to the old loop for all 29 shaders, and for 300,000 random strings made from
sampler,2D,3D,float4,texsize_,(and whitespace.Added unit tests for
EraseRegexMatches(), including a case where an erase creates a new match earlier in the string.