Is CIL ldstr a replacement for a constant string reference. Interval during JIT / AOT compilation?

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.

+5
source share
1 answer

Long answer: yes. Becomes the only MOV registry, imm command at runtime, remember to use a debugger that can show you the disassembly so you don't have to worry about how the metadata token and jitter work. - Hans Passant

+1
source

Source: https://habr.com/ru/post/1238779/


All Articles