Open smedilol opened 2 years ago
The .NET framework has its own implementation for ImmutableList, unfortunately it is available starting with .NET 5...
Depending on the result of #2442, this issue might not be necessary.
The PR #2575 contains small changes to help migrate to .NET implementation of ImmutableList, se wtill have to track and adpat all usages of our ISearchableReadOnlyList<T>
.
After migration check performance gain between original code and MS code.
What is the current problem
If you look at
CodeElementTokenizer
with a Profiler, you'll see that iteration ofImmutableList
is slow. This is the same if you use direct index access to an element ot theImmutableList
. TheImmutableList
is iterated multiple times by the paser. Most parser step and the diagnostics can iterate it.The parser should use ISearchableReadOnlyList interface which wraps our ImmutableList class. But there are several cast of ISearchableReadOnlyList to ImmutableList.
Describe the solution you'd like
As we need to update our list of
CodeElementLine
: insert, update or remove at a specified index, theImmutableList
is the better choice. A LinkedList is not accessible directly with a index. At least not in a fast way.After a simple test, it's faster to copy the
ImmutableList
to another list and then iterate over this list. The solution is to copy theImmutableList
to a simple implementation ofISearchableReadOnlyList
backed by a simpleList
. Of course this implementation should prevent any modification to the list.Technical
ImmutableList
byISearchableReadOnlyList
if only the interface is needed.ImmutableList
toCompilationDocument
to manage text update step.ISearchableReadOnlyList
backed by a simpleList
and use it in all step of the parser aftertext update
step.How to test automatically We can use the same tests made for #2235 and checks the previous version of the Document Snapshot to be sure that each version is immutable.