What can cause gradle daemon to use huge amounts of ram and how to diagnose?

I have a pretty large multi module Scala project.

Since upgrading gradle from version 4.x to 6.6.1 I have noticed, the ram usage for gradle daemon has shot up massively. It used to be it would happily compile up with org.gradle.jvmargs having -Xmx2G, now it runs out of heap space unless I set at least -Xmx8G. It is also a fair bit slower.

This alone isn’t much to go off, so I am not asking for the resolution to my problem, instead I just want to understand how to analyse what is going on.

What are the main ways the gradle daemon can end up using a lot of RAM? How can I effectively identify what is using up all the space?