Understanding of .NET internal StringBuilderCache class configuration

后端 未结 2 2629
情歌与酒
情歌与酒 2021-02-20 16:03

When I was looking at decompiled .NET assemblies to see some internals, I\'ve noticed interesting StringBuilderCache class used by multiple framework\'s methods:

2条回答
  •  日久生厌
    2021-02-20 16:48

    It is a per-thread cache so a low number is expected. Best to use the Reference Source for questions like this, you'll see the comments as well, which looks like (edited to fit):

        // The value 360 was chosen in discussion with performance experts as a 
        // compromise between using as litle memory (per thread) as possible and 
        // still covering a large part of short-lived StringBuilder creations on 
        // the startup path of VS designers.
        private const int MAX_BUILDER_SIZE = 360;
    

    "VS designers" is a wee bit puzzling. Well, not really, surely this work was done to optimize Visual Studio. Neelie Kroes would have a field day and the EU would have another billion dollars if she would find out :)

提交回复
热议问题