godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Implement memory profiling and debugging in GDScript #8143

Open elinfame opened 12 months ago

elinfame commented 12 months ago

Describe the project you are working on

A multiplayer strategy game for the web and desktop.

Describe the problem or limitation you are having in your project

I am subclassing Objects and References for my own custom types, but cannot be sure that I am properly freeing them in all cases. There is currently no way to debug memory issues or profile memory at the GDScript level (e.g. leaks, allocations, zombies). System tools on the target platforms do not have visibility into GDScript objects and require a different tool per platform.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A tool similar to Xcode Instrument's Leaks/Allocations/Zombies, or browser inspectors' Memory tab, which lets you observe the same. This would let me verify that during a given (manual) test run, objects are being freed appropriately, when I expect them to be, and drill into ones that aren't.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

See https://developer.chrome.com/blog/memory-inspector/ and and here for what this might look like.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not that I'm aware of.

Is there a reason why this should be core and not an add-on in the asset library?

I'm not sure but I imagine it requires a deep integration with the language / VM implementation.

ghost commented 12 months ago

I can't speak to the web side of this issue, but I recently resolved a memory leak thanks to a warning by GUT complaining about orphaned nodes. If you start Godot with --verbose, that should give you more information about orphaned nodes in the output. Node.print_orphan_nodes() may also be of help. This is not a full profiler, but it may help with memory issues.

Calinou commented 11 months ago

See the memory allocation monitor that was mentioned in https://github.com/godotengine/godot/issues/62291#issuecomment-1162196287. It's implemented in the linked Godot 3.x fork but needs a port to Godot 4 before it can be submitted as a pull request.