If it's using string optimizations due to short strings, you're cutting allocations in almost half I believe, as well as putting said strings on the stack instead of the heap which will give... significant performance gains. Short strings in the C++ standard library can be crazy fast.
It doesn't merely cut allocations in half; it cuts them to zero.
Do you mean allocations as in heap? If so yeah, I guess I should have stated it better as it still needs to put space on the stack for the short string.
The stack space for the whole function call is allocated in one step. You only get individual allocations when you are messing around with variable length arrays or alloca.
For Java did you try a second run using CDS and PGO data?
I ran mine in JMH which does a bunch of warmup iterations, hopefully enough to trigger full JIT