-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Default onBeforeCompile=null to reduce unnecessary calls to programCache.getProgramCode() #17117
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
Conversation
|
For reference: The additional call of Um, it's a bit inconsistent if |
|
Thanks for the reference. The user API will be the same anyway, since only the renderer calls |
Sorry, but that's technically not true. The default value will be different and |
|
Right, but which currently possible/sensible use cases will break? |
|
You're right, there is actually no reasonable scenario where user code might break. I'm still a bit unsure about the resulting differences between |
|
I understand. I have not presented a running example that demonstrates a significant speedup either, though I am almost sure it is possible to make one. (That would make this tiny change a somewhat larger project.) Who do we/you know that struggles with long scene init time? |
Can't you just setup a scene with many different materials? |
I forgot to correct the
Yes... I suppose so. Everything takes time, though, and I don't strictly have that. Also, when programatically generating several similar materials, I may encounter browser optimizations that invalidate some conclusions. I may give it a try soon, though. Maybe now. |
|
Yes, |
|
Stress test comparison that shows it is possible to get better performance with the patch: This is a rather extreme test with 300 000 RawShaderMaterial instances made from the same extremely simple code and applied once to a shared geometry.
|
I was no referring to this approach, it is until primary... but toString method is created after a function onBeforeCompile making compatible with this code. three.js/examples/jsm/nodes/materials/NodeMaterial.js Lines 31 to 51 in b163e54
|
|
Oh, of course! Now I remember that I found out that yesterday anyway... Any risk that other power users have code that will break? Hm. |
|
This PR actually became obsolete because of the refactoring of #18279. So an additional invocation of |
|
Just curious, i'd be interested if the empty function was referenced from a single I think the way it's consolidated in @Mugen87 PR is a better fix for this. I'm interested in what But yeah, if this were still valid, without the other PR, just from a JS standpoint, i think things could be kept consistent (without |
The price of the change is having to check for the existence of onBeforeCompile before calling it. The gain is avoiding an extra run of
programCache.getProgramCodeon each compile. This call may have a very small footprint compared to the typical compilation stage, but I woud expect the existence check to have an even smaller footprint. It looks like the extraprogramCache.getProgramCodecall was added after the decision was made to have an empty function as default. I have not tested performance in any different scenarios, though. Update: I have tailored a scenario further down which demonstrates an improvement.Also, I have not paid much consideration to the TypeScript declarations. A quick Google search tells that there is a flag for strict handling of
nullandundefinedvalues, but otherwise they are valid values for anything.