-
-
Notifications
You must be signed in to change notification settings - Fork 35.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
Core: Switch to this.is* = true. #24047
Conversation
|
Please also do the same for other classes that are using prototype, like KeyframeTracks. |
|
Oh ok, didn't notice. |
There's a few more uses of In WebGLUniforms, HemisphereLight, Interpolant, and Color. Inside the animation system there's quite a lot, not just in keyframe tracks, so that should probably be handled in its own PR. |
I'm fine with this change. Eventually we should not access
Yes. Let's focus this PR just on the |
Thanks! |
I think this PR missed WebGL1Renderer... I think there should be one more PR to fix remaining prototype accesses. I think those are |
It seems this statement goes too far. Let's remove |
Very often it does not make sense to have it - e.g. in cases like |
It was intetionally left out, the |
Good to know! Eventually, |
* Revert to this.is* = true * Put back local variables * Update tests * Add missing this.is* property * Update Color.js Co-authored-by: Michael Herzog <[email protected]>
Related issue: #24006, Reverts #21293
Description
As illustrated by @Rich-Harris in this tweet (although let's not use class properties yet, we tried in the past).
The reason why three.js is using
*.prototype.is* = true
is to share memory across all instances by using the prototype.However in the real world, having the
is*
boolean in the prototype or the instance, makes no difference at all (a boolean is just 1 byte of memory after all).Here is a stress example with 10000 instances of the same material.
The first two snapshots are of the page with the
*.prototype.is* = true
, the last two snapshots are withthis.is* = true
. Somehow the memory decreased withthis.is* = true
.Here is the code of the example in case anyone else wants to test.
The root issue is caused by bundlers having difficulty tree-shaking classes with
.proprtype.*
accessors. The current status is:But most importantly this makes importing from
'three'
same as importing from'three/src/Three'
, so no more people rambling about this on twitter.