Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SE: Add caching for reusable data structures #6964

Open
9 of 16 tasks
martin-strecker-sonarsource opened this issue Mar 21, 2023 · 0 comments
Open
9 of 16 tasks

SE: Add caching for reusable data structures #6964

martin-strecker-sonarsource opened this issue Mar 21, 2023 · 0 comments
Assignees
Labels
Area: C# C# rules related issues. Type: Improvement Making existing code better.

Comments

@martin-strecker-sonarsource
Copy link
Contributor

SE is based on the graph flow engine and adds branching on top of it. This results in big data structures for complicated code. We should investigate the hotspots here and add caching for our immutable types that represent the same state.

  • Maintenance: SymbolicValue ctor must be private SE: Make SymbolicValue ctor private. #6978
  • Maintenance: Remove SymbolicValue This SE: Remove SymbolicValue.This #6980
  • Maintenance: EnumerableContentHash must take order into account SE: Enumerable ContentHash for ordered and unordered sets #6979
  • Cache SymbolicConstriant
  • Cache SymbolicValue SE - Add cache for SymbolicValues #6913
  • Cache SymbolicValue.GetHashcode() SE - Add cache for SymbolicValues #6913 (comment) SE: Caching: Cache "GetHashCode" for SymbolicValue #6968
  • Caching ProgramState.GetHashcode() SE: Maintenance: Cache GetHashCode for ProgramState #6983
  • Unroll HashCode.DictionaryContentHash() (Allocations caused by Aggregate are in the top 5. Should be revisited after Hashcodes are cached). SE: Maintenance: Allocation free hash code implementation for immutable dict #7012
  • Caching ProgramState.ToArray()
  • Caching ProgramState
  • Rethink ProgramState.AddVisit: The add operation allocates a lot (10% in terms of object count and MB of the overall allocations including the analyzer runner and the Roslyn analysis) of System.Collections.Immutable.SortedInt32KeyNode<> (Options: precompute the dictionary and use a mutable dictionary instead. We can remove the visit tracking from ProgramState and move it to a local in "Execute" instead or make it mutable in ProgramState. Either would also avoid new copies of ProgramState. Doesn't work due to the way visit count works.) Potential savings by removal of VisitCount: SortedInt32KeyNode down from 75.324 to 56.054 number of objects (down to 75%). Overall: 96,5% after removal (number of objects and MB)
  • Change the return type of PreProcess, OperationDispatcher.Process, and PostProcess from SymbolicContext[] to readonly struct SymbolicContexts(SymbolicContext first, SymbolicContext second, SymbolicContext[] others). This would pass SymbolicValue via the stack instead of the heap (Potential savings: NoOfObjects: SymbolicValue[]: 17.221, List<SymbolicValue> 10.000 ~4% of the total; 1.000.000 byte in total). Background: We almost always return 0, 1, or 2 states but never more than that at the moment. With the SymbolicContexts we would reserve space on the stack for up to two states and any additional states would be passed via the others array. The SymbolicContexts would implement the enumerable pattern (also as a struct) so we can foreach over it (but I would not implement IEnumerable, so we don't Linq over it by accident). SE: Pass states per stack #7059
  • There are a lot of state machine instances created by yield return in ProcessBranching and ProcessOperation. We may consider moving to some stack-based solution if possible.
  • SonarAnalyzer.CFG.Roslyn types (e.g. ControlFlowGraph). Measure allocations and consider turning them into readonly structs
  • SonarAnalyzer.CFG.Roslyn types Use compiled expressions like with LightupHelpers.CreateSyntaxPropertyAccessor to avoid the overhead of PropertyInfo.GetValue.
  • Unroll SymbolicCheckList.InvokeChecks (SelectMany related types are in the top 5 collected types list) SE: Maintenance: Unroll SymbolicCheckList.InvokeChecks #6982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: Improvement Making existing code better.
Projects
None yet
Development

No branches or pull requests

2 participants