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

Performance improvements to CoberturaParser #691

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

afscrome
Copy link
Contributor

@afscrome afscrome commented Aug 28, 2024

  • Try and re-use already filtered XElements in CoberturaParser rather than re-filtering the xml document all over the place.
  • Optimise some string.Concat in ProcessClass method which were showing up in hot paths in profiling

In local testing, this reduces parsing time from roughly 11.5secs to 9 seconds, as well as reducing memory allocations from 17GB to 2.2GB.

For reference below is the code I tested with

string[] coverageFiles = { /* Test files */ };
CoverageReportParser parser = new CoverageReportParser(1, 1, [],
    new DefaultFilter([]),
    new DefaultFilter([]),
    new DefaultFilter([]));

ReadOnlyCollection<string> collection = new(coverageFiles);
var stopwatch = Stopwatch.StartNew();
var results = parser.ParseFiles(collection);

var lines = results.Assemblies.Select(x => x.CoveredLines).Sum();

Console.WriteLine($"TIME: {stopwatch.Elapsed}, LINES: {lines}");

And the following show the GCStats results from PerfView

Before

  • Runtime Version: V 8.0.824.36612
  • CLR Startup Flags: 8388611
  • Total CPU Time: 39,242 msec
  • Total GC CPU Time: 3,510 msec
  • Total Allocs : 17,090.138 MB
  • Number of Heaps: 1
  • GC CPU MSec/MB Alloc : 0.205 MSec/MB
  • Total GC Pause: 4,301.4 msec
  • % Time paused for Garbage Collection: 36.0%
  • % CPU Time spent Garbage Collecting: 8.9%
  • Max GC Heap Size: 740.916 MB
  • Peak Process Working Set: 808.591 MB
  • Peak Virtual Memory Usage: 2,480,934.539 MB

After

  • Runtime Version: V 8.0.824.36612
  • CLR Startup Flags: 8388611
  • Total CPU Time: 19,845 msec
  • Total GC CPU Time: 2,029 msec
  • Total Allocs : 2,204.929 MB
  • Number of Heaps: 1
  • GC CPU MSec/MB Alloc : 0.920 MSec/MB
  • Total GC Pause: 2,350.1 msec
  • % Time paused for Garbage Collection: 29.2%
  • % CPU Time spent Garbage Collecting: 10.2%
  • Max GC Heap Size: 732.562 MB
  • Peak Process Working Set: 796.983 MB
  • Peak Virtual Memory Usage: 2,480,932.901 MB

- Try and re-use already filtered XElements in `CoberturaParser` rather than re-filtering the xml document all over the place.
- Optimise some `string.Concat` in `ProcessClass` method which were showing up in hot paths in profiling

In local testing, this reduces parsing time from roughly 11.5secs to 9 seconds, as well as reducing memory allocations from  17GB to 2.2GB.
@danielpalme
Copy link
Owner

Thank you! I will review and merge your PR as soon as possible.

@danielpalme danielpalme merged commit 57a7c43 into danielpalme:main Aug 28, 2024
6 checks passed
@afscrome afscrome deleted the parser-improvements branch September 5, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants