Yield to the defer agent per mesh assignment during instantiation - #823
Closed
nickdnk wants to merge 1 commit into
Closed
Yield to the defer agent per mesh assignment during instantiation#823nickdnk wants to merge 1 commit into
nickdnk wants to merge 1 commit into
Conversation
Hierarchy population honored the frame budget only between nodes; a node carrying many mesh assignments (multi-material meshes) populated them all in one un-yielding callback (measured: 70 ms frames on large scenes, 0.15 ms max after). No public API change; behavior identical under UninterruptedDeferAgent.
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.
Same kind of performance related issue as #822 - if you have one very big object (say you are not the author and cannot easily split it), its instantiation can cause a stutter. Instantiation already yields to the frame budget per node, but a single node with many mesh assignments (multi-material meshes) populates them all in one go. This yields per assignment too, tunable by the existing frame budget logic.
Note: Everything below AI generated.
Problem
InstantiateSceneInternalhonors the defer agent's frame budget between nodes (IterateNodesawaitsBreakPoint()per node), butPopulateHierarchypopulates all of a node's mesh assignments in one un-yielding callback. A node with many assignments (any multi-material mesh; CAD/archviz-style content routinely has dozens per node) blows the frame budget with no way for the defer agent to intervene.Fix
Make the population callback
Task-returning and yieldDeferAgent.BreakPoint()after each mesh assignment — the same contract node iteration already follows, one level finer. ThePopulateHierarchyprofiler sample now wraps one assignment instead of a whole node, so captures attribute per assignment.No public API change (the callback is a local function). Under
UninterruptedDeferAgent,BreakPoint()is a no-op and behavior is byte-identical.Measurements
Unity 6000.5.3f1, macOS (Apple Silicon), Mono development player, streaming scenes with high-node-count glbs (up to ~40 primitive clusters per node):
PopulateHierarchysampleBehavior notes for review
meshNumeration, and theEndScenetiming (where skins/animations bind) are unchanged.