Avoid repeated _copy_on_write() calls in Array::resize()#110535
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Sep 16, 2025
Merged
Avoid repeated _copy_on_write() calls in Array::resize()#110535Repiteo merged 1 commit intogodotengine:masterfrom
_copy_on_write() calls in Array::resize()#110535Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
Updated Array::resize() to call ptrw() once before looping to initialize typed array elements, instead of accessing each through .write[].
Ivorforce
approved these changes
Sep 15, 2025
Member
Ivorforce
left a comment
There was a problem hiding this comment.
Looks good to me.
The function isnt optimal even with this change, but this is an obvious improvement. Good find!
Calinou
approved these changes
Sep 15, 2025
Member
There was a problem hiding this comment.
Tested locally, it works as expected. Code looks good to me.
PC specifications
- CPU: AMD Ryzen 9 9950X3D
- GPU: NVIDIA GeForce RTX 5090
- RAM: 64 GB (2×32 GB DDR5-6000 CL30)
- SSD: Solidigm P44 Pro 2 TB
- OS: Linux (Fedora 42)
Using a release export template with LTO.
Before
resize_int: 125ms
resize_str: 191ms
After
resize_int: 35ms (3.57x faster)
resize_str: 112ms (1.71x faster)
Contributor
|
Thanks! |
Contributor
|
Cherry-picked to 4.5 |
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.
Updated
Array::resize()to callptrw()once before looping to initialize typed array elements, instead of accessing each through.write[].This makes
Array.resize()in gdscript around 2-4x faster for typed arrays, will vary depending on type and size. Compared with gdscript below:old:
new: