What is the "fast memory allocator" for "local strings"?

The “new performance improvements in 2020.2” blog post says this:
The team replaced lots of slow string memory allocations with temp memory labels, for strings that only exist within a single frame. In practice, most strings in Unity exist only as local variables within a single function call, so they can use a fast memory allocator. Most string utility functions now use temp memory.

Working more efficiently with strings is highly relevant to my interests. Can you elaborate on what you’re doing? Is this on the native C side, or is this happening in CLR code? If the latter, is this just using stackalloc in unsafe code, or some other mechanism?

The fast allocator is mainly only usable on the native side for strings, but we do expose some of the same features in script for some non-string types.

For example, the fast memory allocator is very similar to what is used if you create a NativeArray with the Allocator.Temp parameter.

2 Likes