perf: optimize instanced buffer batching - #269
Merged
llsansun merged 4 commits intoAug 14, 2026
Merged
Conversation
Code Size Check Report
Interface Check ReportThis pull request does not change any public interfaces ! |
Contributor
Author
|
@cocos-robot run test cases |
|
@llsansun, Please check the result of
Task Details |
|
@llsansun, Please check the result of
Task Details |
Contributor
Author
|
@cocos-robot run test cases |
star-e
approved these changes
Aug 14, 2026
|
@llsansun, Please check the result of
Task Details |
|
@llsansun, Please check the result of
Task Details |
6 tasks
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.
Re: #
Changelog
Performance
This change optimizes the existing instancing path without changing when instancing is enabled. Materials still need to enable
USE_INSTANCINGexplicitly.Before this change, each incoming instanced model searched through all existing instance groups linearly to find a compatible group. As the number of instance groups increased, the CPU cost of
InstancedBuffer.merge()grew accordingly.After this change, compatible instance groups are cached by a key generated from the input assembler, lighting map, reflection probe textures, reflection probe type, and instance attribute stride. This allows the merge path to quickly find candidate groups and only scan groups that share the same compatibility key.
In addition, buffer uploads now use the valid instance data size,
instance.count * instance.stride, instead of uploading the whole allocated backing buffer. This avoids uploading unused capacity when the instance buffer has grown but is not fully occupied.Before profiling result:

After profiling result:

Continuous Integration
This pull request:
Compatibility Check
This pull request:
Test Plan
USE_INSTANCINGenabled.InstancedBuffer.merge()cost is reduced.