Silly question for #dotnet folks. Does Release mode automatically call `String.Intern` on strings? I only ask because I ran a benchmark, and doing it explicitly versus not doing it amounts to identical results.

It might also be a release optimization for `StreamReader`.

@khalidabuhakmeh this implies you have string literals in your code, for every line of the file. Odd scenario.

@davidwengier doh, missing more context.

The "reader" is reading from a log file that might have duplicate lines (which is common).

Hope that clears it up?

@khalidabuhakmeh oh, you want to dedupe strings in memory? I think you just want a dictionary. AFAIK string.Intern doesn't add to the intern pool.

@davidwengier the on-method documentation says it does 🤔

And yes, a local pool would be the best option.

String Interning - To Use or Not to Use? A Performance Question

I recently join a new team and one of the projects was having a high memory footprint issues. There are a few mitigations put in place and one of them was to de-duplicate strings by using string interning.

Dissecting the Code
@davidwengier @khalidabuhakmeh basically never use String.Intern. If you need to dedupe, roll your own Dictionary or ConcurrentDictionary.
@waltza @KirillOsenkov @khalidabuhakmeh a hashset will tell you if the string is in the pool, but it won't help you return it from the pool efficiency. However if your hashset has a GetKeyByKey method, then go for it!
@KirillOsenkov @davidwengier funny this is similar to the post I was thinking of writing 😅