Good question. I looked at this and found my VM was swapping like crazy. Upon investigation it appears that's because, since the patch creates a memory context per aggregated group, and in this case I've got 1 million of them, it means we create 1 million context, which are ALLOCSET_SMALL_INITSIZE (1KB) in size, which means about 1GB of memory, which is more than my VM likes.
Really? Where do we create the memory context? IIRC string_agg uses the aggcontext directly, and indeed that's what I see in string_agg_transfn and makeStringAggState.
Yeah, all this is talk is relating to Robert's expandedstring-v1.patch which changes string_agg to use text and expanded-objects. This also means that a memory context is created per group, which is rather a big overhead.