PERF: avoid string allocations
Merge pull request #17669 from SamSaffron/optimise_memory

PERF: avoid string allocations