TypeCobolTeam / TypeCobol

TypeCobol is an Incremental Cobol parser for IBM Enterprise Cobol 6 for zOS syntax. TypeCobol is also an extension of Cobol 85 language which can then be converted to Cobol85.
Other
78 stars 26 forks source link

Optimize access to our ISearchableReadOnlyList / ImmutableList #2236

Open smedilol opened 2 years ago

smedilol commented 2 years ago

What is the current problem

If you look at CodeElementTokenizer with a Profiler, you'll see that iteration of ImmutableList is slow. This is the same if you use direct index access to an element ot the ImmutableList. The ImmutableList 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, the ImmutableList 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 the ImmutableList to a simple implementation of ISearchableReadOnlyList backed by a simple List. Of course this implementation should prevent any modification to the list.

Technical

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.

fm-117 commented 2 years ago

The .NET framework has its own implementation for ImmutableList, unfortunately it is available starting with .NET 5...

smedilol commented 1 year ago

Depending on the result of #2442, this issue might not be necessary.

fm-117 commented 1 year ago

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.