Skip to content

FastString: Reimplement in terms of pointer equality

Matthew Pickering requested to merge wip/faststring-allocs into master

GHC allocates a lot of FastStrings 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.

  1. Unique: Computed from the pointer
  2. Equality: Computed directly by comparing the pointer
  3. Length: Only used in 3 places, so the overhead is not worth it.
  4. 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.

Merge request reports