-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shader define expression optimization #13936
Shader define expression optimization #13936
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/13936/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/13936/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/13936/merge#BCU1XR#0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Could you run additional tests with some of the PGs in the visualization test list (try to use the heaviest PGs), just to have a larger corpus of tests?
packages/dev/core/src/Engines/Processors/Expressions/shaderDefineExpression.ts
Outdated
Show resolved
Hide resolved
packages/dev/core/src/Engines/Processors/Expressions/shaderDefineExpression.ts
Outdated
Show resolved
Hide resolved
packages/dev/core/src/Engines/Processors/Expressions/shaderDefineExpression.ts
Outdated
Show resolved
Hide resolved
@Popov72 I ll do a round of review once you validate the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a huge fan of the static way the cache is working. basically it only grows to 50000 and then no cache. I wonder if there would be a way to not keep oldest entries or rotate them instead ?
Of course there are many things that we can make with memoization cache, but the current value seems a huge limit and this property is not private, so it can be changed, if developer would like to increase cache size. |
would be cool as long as it does not slow things down @Popov72 any thoughts ? |
To save performance we should remove outdated cache pretty rarely, not each cache access. |
Love the idea of cleaning like this !!!! |
Let s ensure the cache write access for the date won t slow things more than it was before the PR |
If InfixToPostfixCacheLimitSize have not enough size and clearCache calls every time, than it has slow down. For example, my scene utilize 168 cache items while loading and if InfixToPostfixCacheLimitSize=50 (just fifty items) and every fiftieth half items in cache removes that it really slow down to 27.86ms for all function calls and 15.37ms for first 10 000 calls - it is better than before PR, but not good as it possible. But when InfixToPostfixCacheLimitSize has enough size I measured 5.57ms for first 10 000 calls and 12.13ms for all calls. |
In my scene with 50+ shaders the ShaderDefineExpression.infixToPostfix was called 15 000–35 000 times while scene is loading. In average for one loading it takes 54.28ms for all calls and 34.39ms for first 15 000 calls.
After optimized from this PR I achieve next result: 9.68ms for all calls and 7.09ms for first 15 000 calls.
I made two simple changes:
infix
does not contain operators, then it will not be modified, so we can return it as is.For safety work with memory I add a limit for memoize cache as 50000 entries. In my case the 100 entries takes 6504 chars of memory, so with the basic interpolation it might be around 640 KB for 50 000 entries. As all we know, 640K ought to be enough for anybody :)
So, just with this two changes performance of the function was boosted 5.6x times and for my middle (as I think now) scene it saves 45ms (or almost 3 frames) for loading.