This repository was archived by the owner on Feb 25, 2025. It is now read-only.
[Impeller] fix quadradic behavior in polyline creation #36680
Merged
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.
Incrementally reserving vector capacity leads to quadradic behavior in polyline creation. I think that reserve only ensures that vector has the specified capacity, it doesn't trigger the normal doubling of the storage space. Each time a polyline component is converted and we request the vector to reserve . Because it won't have resized more than the prior component required, we force the existing vector to copy all of the previous components to allocate the backing memory. This is roughly N2 in the number of components.
By removing this reserve and letting the normal vector allocation strategy run, we get the expected linear-ish behavior.
With fix, this frame takes ~20ms to render. Without the fix, it takes ~180ms. Adding too many more rects and it won't finish.
Example app: