Glossary
What is string interning?
String interning means keeping a table of every distinct string and always reusing the stored copy. If "hello" is interned, every "hello" in the program is the same object, so checking two strings for equality is a single pointer comparison instead of a character-by-character loop.
Why a VM wants it
Variable names, method names and field names are looked up constantly. With interning, a hash table keyed by strings can compare keys by pointer, which makes globals, fields and method calls fast. The price is a lookup in the intern table every time a new string is created.
In clox
Chapter 20, Hash Tables builds an open addressing hash table and uses it as the intern table. Later, the garbage collector has to treat that table as weak: an interned string nobody else uses must still be freed.
Questions
Do real languages intern strings?
Many do for identifiers and literals, and some intern all strings. Java interns string literals, for example, and exposes intern() for others.