Skip to content

[Performance]: BuildEventArgsWriter.WriteProjectItems spends a large % CPU time on CopyOnWriteDictionary #10490

@yuehuang010

Description

@yuehuang010

Issue Description

While profiling BinaryReader/Writer, I have noticed a large % of time in creating CopyOnWriteDictionary/ImmutableDictionary. This event is triggered from LogProjectEvaluationFinished() where it enumerates through all the items and metadata. This is a lot of data but it should not be as much seen. The time is spent in creating the list of metadata using CopyOnWriteDictionary/ImmutableDictionary but it discard shortly afterwards.

Steps to Reproduce

I used a medium to large solution of 200-300 projects to run the clean target (on an already cleaned build). This focuses the time spent on Project Evaluations.

Message me if you like access to my specific solution.

Data

image
image

Analysis

I have commented out the writer of foreach (var kvp in item.EnumerateMetadata()) in BuildEventArgsWriter.cs. The repro improved from 10s to 6s. It is hard to confirm if 6s is correct final performance, as there are a lot of Lazy or delayed evaluations, but it should be closer to 6s or 7s than 10s.

Versions & Configurations

No response

Regression

  • yes
  • no

Regression Details

No, but it is hard to confirm as this is my first time profiling this code path.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions