Replies: 2 comments
-
See the pull request for this at godotengine/godot#100452. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, I wrote my 2 cents in the PR. Hope this helps. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In C#, StringNames and NodePaths can be a footgun for garbage collection issues which cause performance spikes.
This can be a very insidious issue because of implicit casting:
To test the extent of the issue, I wrote the following code:
It creates, uses and discards 10,000 StringNames per physics frame, to be garbage collected. This uses FusionCache, but any capped-size dictionary could be used.
When
![GodotStringNamesNoCache](https://private-user-images.githubusercontent.com/65855333/370881722-8d62b676-7493-46f5-84af-310db8147f04.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MTc3NzksIm5iZiI6MTczODkxNzQ3OSwicGF0aCI6Ii82NTg1NTMzMy8zNzA4ODE3MjItOGQ2MmI2NzYtNzQ5My00NmY1LTg0YWYtMzEwZGI4MTQ3ZjA0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDA4Mzc1OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA1NzU3YjA3MTI3ZmVkYzhkM2ZhYjZhNjQ3NDYzMTRkMWQ2ZTk1ZWY2MmM1ZTZjNzk0MGJiNzA0Y2Y2NWJmOTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.RY0AtXZEhOCS5sHfU0XErh5yb3kFiK6w9dR6st5Cp20)
UseCache
is false, I get consistent 30ms spikes:When
![GodotStringNamesCache](https://private-user-images.githubusercontent.com/65855333/370881752-2955f34b-acc6-4e74-8431-282292fab2ce.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MTc3NzksIm5iZiI6MTczODkxNzQ3OSwicGF0aCI6Ii82NTg1NTMzMy8zNzA4ODE3NTItMjk1NWYzNGItYWNjNi00ZTc0LTg0MzEtMjgyMjkyZmFiMmNlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDA4Mzc1OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVkYzI2ZmFiNDM5YzRkMWEyMDBjMDA4ZmYyOWQ2NDU5NzFmZDUxYjg0MGQ5OTY0ZmMzMDBiMGQzMDEwZDdmYmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.M2wlmRBk-rW33KwpGdfnZUASMO0_eQceAYXxkEy5LgU)
UseCache
is true, I get a steady 17ms:Ideally, the C# API would exclusively use strings rather than StringNames. But until this is implemented, there should be a better StringName/NodePath API.
In my code, I've been doing this:
Then I can do:
However, I think this would be better implemented in the API itself, because of reduced footguns and simpler syntax.
Here's the StringName cast according to the reflector:
This could be changed to this:
Here's the project I used for profiling: stringnamestest.zip
Beta Was this translation helpful? Give feedback.
All reactions