FastString: Reimplement in terms of pointer equality
GHC allocates a lot of FastString
s when compiling so reducing the
overhead of a FastString will result in a large decrease in allocations.
Therefore we remove all the unnecessary fields from the FastString.
- Unique: Computed from the pointer
- Equality: Computed directly by comparing the pointer
- Length: Only used in 3 places, so the overhead is not worth it.
- HasZEncoding: Caching the zencoding for a string should be localised to code generation rather than any consumer having to pay a large allocation penalty.
Comparing pointer equality is safe as the string table guarantees that each string is only allocated once. As the memory is pinned, we don't have to worry about GC moving around the locations of the strings.
Ticket: #17059
Thanks to Jamie (Hanue) Willis for suggesting the idea of using pointer equality.