Rendering: Pre-allocate light vectors in scene culling #114329
+2
−0
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.
While looking through the rendering code, I noticed that
directional_lightsandlights_with_shadowvectors in_render_sceneare built up withpush_back()without reserving capacity first. Since we already know the upper bound fromscenario->directional_lights.size(), we can avoid the reallocations.It's a small thing, but this runs every frame during scene rendering so it adds up.
Changes
reserve()fordirectional_lightsbefore the loopreserve()forlights_with_shadowinside the directional lights blockBoth use
scenario->directional_lights.size()as the capacity hint, which is the maximum number of elements either vector can have.