I don't know serverless, but recently-ish (few months ago) I was testing Java memory usage on a tiny program. Something like:
public class Main {
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 60; i++) {
System.out.printf("%d\n", i);
Thread.sleep(1000);
}
}
}
After spamming as many flags as I could find (literally listing all possible flags and seeing what looked like a high number, and lowering it), I could only get this program to use 307MB VIRT and 40MB RES memory.Unfortunately I didn't save the flags I used.
That's more or less on par with the equivalent Node.js program on my PC (Node.js actually uses a bit more RES memory, 44MB).
So I guess as long as you can (and want to) spam a lot of flags, it's feasible to lower memory usage.
Disclaimer: Not a Java dev.