Say I have code that needs to be optimized, but easy to debug at the same time. Therefore, I would assign a string to each value I use. Will the string affect the big performance, or does it turn into a permalink obtained from string.Intern during JIT / AOT compilation, thus turning into one simple instruction?
Example:
In IL it will be ldstr "gazilion lines" .
This during JIT / AOT compilation turns into something like ldsflda string.InternCache.ID_0000647516166 and const string ID_0000647516166 = "gazilion lines"; appends to string.InternCache ?
Yes, I could theoretically study https://github.com/mono/mono , but I have no idea how to find it.
Yes, I mix CIL, C # and everything compiled into CIL, but you get the idea.
Is ldstr guaranteed O(1) ?
Yes, this is the "implementation detail" of the CLR, but it would be reasonable if it were optimized in this way.
source share