Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scenes with lots of nodes close extremely slowly due to excessive JVM Garbage Collector invocations. #651

Open
ImplementsLegend opened this issue Jun 9, 2024 · 2 comments

Comments

@ImplementsLegend
Copy link

Simple scenario:

class Container:Node(){
    init{
        repeat(1000000){
            addChild(Node())
        }
    }
}

Godot runs absolutely fine, but when you try to close it, it takes forever.

Problem is that MemoryManager.cleanup() method invokes garbage collector too much. (at least once for every 256 objects)

internal object MemoryManager {
    /*omitted*/
    fun cleanUp() {
        /*omitted*/
        var begin = Instant.now()
        while (ObjectDB.any { it != null } || nativeCoreTypeMap.isNotEmpty()) { //loops until all objects are cleaned

            forceJvmGc() //runs JVM Garbage Collector
            if (manageMemory()) { //cleans up to 256 objects
                begin = Instant.now()
            }
            /*omitted*/
    }
}

So, to clean up 1000000 nodes, forceJvmGc() will be invoked approximately 4000 times and that takes a long time.

@CedNaru
Copy link
Member

CedNaru commented Jun 13, 2024

It's a known issue that this part of the code is slow. We plan to replace it following this existing proposal:
#508

The direct consequence will be that we won't need to wait for the GC to run when closing Godot anymore.

@kostaskougios
Copy link

I am having as well a slow shutdown when closing my game. I am creating a 3d map with a lot of tile-nodes and I am guessing it is this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants