r/ProgrammingLanguages • u/Creative-Cup-6326 • Mar 31 '26
Using string interning to optimize symbol resolution in compilers
Hey everyone, I'm building a custom compiler from scratch and wanted to talk about how string interning can massively optimize it.
I wrote a short post on my approach using a Dense Arena Interner to turn slow string comparisons into instant O(1) integer checks across the parsing and typechecking pipeline. Would love to hear how you all handle this.
11
Upvotes
View all comments
Show parent comment
2
u/Valuable_Leopard_799 Apr 01 '26
I did say the HashMap is used once for lookup, as do you.
The type interning is neat.
I had a thought, you wanted dense IDs to do fast lookups in scopes for example, but without some hashtable functionality around that lookup you'd have to allocate a large part of the symbol space for every place in the compiler you want to associate things with a symbol.
How would you handle having 100s of symbols and 4 to 5 levels of nested scope? Maybe the Array of Stacks you mentioned could help, hm.