I am always looking at different ways of optimizing application resources in Sitecore. After all, low resources means low cost!!
I came across the concept of String Interning and I got interested into it. Next, I was thinking how can I make use of it in my Sitecore instances. I started digging little bit and I found Sitecore is smart enough to already make use of it. I will share some of the findings in this post.
What is String Interning?
In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable.
What this means is if you have a string object str1 with value "Hello" and then if your code initializes another string object str2 with same value "Hello", string interning will prevent creation of second object for str2 as String Constants Pool already has a string object with same value. It will assign the reference of str1 to str2 and str2 will reuse the object that was created for str1. This obviously saves memory.
Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool. The single copy of each string is called its intern.
How Sitecore implements String Interning?
Sitecore has a Sitecore.Interning.config that configures the interning mechanisms of the Sitecore CEP, and must be enabled on all server roles.
You should enable this file to reduce the memory consumption. This is done by re-using immutable objects (f.e. strings, and IDs ) instead of creating new ones.
Extending of the functionality must be done carefully not to introduce memory leaks. By default, following fields in Sitecore are string interned -
Comments
Post a Comment