Skip to content

Reduce heap allocations in multi-pass scene rendering#9545

Closed
aardgoose wants to merge 7 commits intomrdoob:devfrom
aardgoose:render-allocs
Closed

Reduce heap allocations in multi-pass scene rendering#9545
aardgoose wants to merge 7 commits intomrdoob:devfrom
aardgoose:render-allocs

Conversation

@aardgoose
Copy link
Contributor

Use separate render lists for each scene to avoid array resize and
RenderItem creation every frame when multiple differently sized scenes are
repeatedly rendered with the same renderer.

Exhibited by the rtt example.

RenderItem creation every frame when multiple differently sized scenes are
repeatedly rendered with the same renderer.

Exhibited by the rtt example.

opaqueObjectsLastIndex = - 1;
transparentObjectsLastIndex = - 1;
if ( scene._opaqueObjects === undefined ) {
Copy link
Owner

@mrdoob mrdoob Aug 18, 2016

Choose a reason for hiding this comment

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

Instead of polluting the scene object I would have a internal object in WebGLRenderer like renderLists[ scene.id ]. We used to pollute the scene graph like this. It's handy, but it becomes messy very quickly.

@aardgoose
Copy link
Contributor Author

Modified as requested.

@mrdoob
Copy link
Owner

mrdoob commented Aug 19, 2016

Thanks!

@mrdoob
Copy link
Owner

mrdoob commented Aug 19, 2016

@tschw what do you think about this approach?

@tschw
Copy link
Contributor

tschw commented Aug 20, 2016

Basically seems a very good idea to me.

As already addressed, the renderer should own the data, then it will still work with multiple renderers rendering different views of the same scene. Is there a dispose handler attached to the scene object somewhere? We don't want to bogart the temporaries indefinitely.

Also, I think we should use the WebGLProperties container instead of the array-indexed-by-id stuff in the second commit.

@aardgoose
Copy link
Contributor Author

Ok,

I realised I need to attach a dispose handler to the scene. I'll respin with that and WebGLProperties, still learning the code base... the dispose handler will be basically properties.delete( scene ) in that case unless I am mistaken.

mrdoob added a commit that referenced this pull request Feb 24, 2017
@mrdoob
Copy link
Owner

mrdoob commented Feb 24, 2017

Ended up doing a similar implementation, but also for scene+camera.

@mrdoob
Copy link
Owner

mrdoob commented Feb 24, 2017

Thanks though!

@mrdoob mrdoob closed this Feb 24, 2017
@aardgoose aardgoose deleted the render-allocs branch February 27, 2017 09:24
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 11, 2021

but also for scene+camera.

I know this issue is a few years old but do you remember the motivation behind including the camera?

I've refactored WebGLRenderLists so it uses the same approach like WebGLRenderStates which was introduced in #20422. The commit looks like so: 4c18162

At first sight, it seems including the camera is not necessary since render items are defined by 3D objects which are only present in the scene. Even if multiple cameras render the same scene and discard certain objects because of view frustum culling or different layers configuration, there is no additional GC overhead (because render items are internally cached).

@mrdoob
Copy link
Owner

mrdoob commented Feb 11, 2021

I think it was because renderlists size woulc change multiple times per frame when rendering from different cameras (ie. mirrors). The stack approach is definitely a better solution for that 👍

@mrdoob
Copy link
Owner

mrdoob commented Feb 11, 2021

The commit looks good! Thanks for doing that clean up. We should try merging it soon so we can test it 🙏

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.

4 participants