diff --git a/src/Compilers/Core/Portable/Text/LargeText.cs b/src/Compilers/Core/Portable/Text/LargeText.cs index 9fc77a99eb920..7572861c5f1e2 100644 --- a/src/Compilers/Core/Portable/Text/LargeText.cs +++ b/src/Compilers/Core/Portable/Text/LargeText.cs @@ -238,7 +238,9 @@ private SegmentedList ParseLineStarts() var position = 0; var index = 0; var lastCr = -1; - var list = new SegmentedList(); + // Initial line capacity estimated at 64 chars / line. This value was obtained by + // looking at ratios in large files in the roslyn repo. + var list = new SegmentedList(Length / 64); // The following loop goes through every character in the text. It is highly // performance critical, and thus inlines knowledge about common line breaks diff --git a/src/Compilers/Core/Portable/Text/SourceText.cs b/src/Compilers/Core/Portable/Text/SourceText.cs index 0dac9ac001d04..d58eb8d2b86e7 100644 --- a/src/Compilers/Core/Portable/Text/SourceText.cs +++ b/src/Compilers/Core/Portable/Text/SourceText.cs @@ -1049,7 +1049,9 @@ private SegmentedList ParseLineStarts() return [0]; } - var lineStarts = new SegmentedList() + // Initial line capacity estimated at 64 chars / line. This value was obtained by + // looking at ratios in large files in the roslyn repo. + var lineStarts = new SegmentedList(Length / 64) { 0 // there is always the first line };