A string interning library for Go
intern has a number of benefits
- It deduplicates strings. if you have data that references identical text in very many different places if may significantly reduce the amount of memory used for the strings.
- It stores the strings in a way that reduces the load on the garbage collector.
- It allows you to store an int ID for the string instead of the string itself. This is considerably smaller, and again is GC friendly.
i := intern.New() hat := i.Save("hat") fmt.Printf(i.Get(hat))