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

Extend property assignment event (The feature is opted-out by default) #11106

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

YuliiaKovalova
Copy link
Member

@YuliiaKovalova YuliiaKovalova commented Dec 6, 2024

Fixes #2711
and connected to KirillOsenkov/MSBuildStructuredLog#839

Context

The feature is opted-out by default due to perf considerations !
This implementation covers cases:

  • property coming from a command-line argument (e.g. /p:) (previously had a Global source)
  • as an output of a target
  • as an output of a task
  • exact property location if it comes from xml during evaluation

Also, the message formatting logic was changed for PropertyReassignmentEventArgs and PropertyInitialValueSetEventArgs to have it optimized for existing deduplication logic.
The event save all the unique data and format it on the receiving side (e.g. LogViewer).

The measurements were taken for the latest OrchardCode

No property init/reassignment logged Property init/reassignment logged
Binlog Size 162.932 KB 196.269 KB
Build Time 533.4s 579.0s
BinLog allocations Total opening time: 1:00.416, Loading: 27.490 s, Analyzing: 7.036 s, Indexing: 21.540 s, Reading files: 400 ms, Allocated: 35,920,765,696 bytes, Nodes: 219,551,777, Strings: 436,574 Total opening time: 1:28.087, Loading: 39.449 s, Analyzing: 6.991 s, Indexing: 37.275 s, Reading files: 403 ms, Allocated: 39,507,530,416 bytes, Nodes: 224,560,814, Strings: 489,542

Conclusions:

Metric Analysis
Binlog Size The binlog size increased from 162.932 KB to 196.269 KB, an increase of about 20%.
Build Time The build time increased from 533.4s to 579.0s, an increase of approximately 8.5%.
BinLog allocations Memory Allocation: Increased from ~35.9 GB to ~39.5 GB (+10% memory usage), Node and String Count: Nodes increased by 2.3% and Strings increased by 12.1%, Loading time increased significantly (from 27.5s to 39.4s), Indexing time increased (from 21.5s to 37.3s)

@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review December 11, 2024 15:24
Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have couple comments to consider.

The main thing before signoff - this is currently not a default behavior (neither with /bl) - correct? Property tracking needs to be explicitly opted in - right?
Please add that info into the PR description (as otherwise the 8.5% perf hit might be bit concerning and might need a bit more deeper look)

src/Build/Evaluation/Evaluator.cs Outdated Show resolved Hide resolved
src/Shared/EnumUtilities.cs Outdated Show resolved Hide resolved
@YuliiaKovalova YuliiaKovalova changed the title Extend property assignment event Extend property assignment event (The feature is opted-out by default) Jan 6, 2025
@KirillOsenkov
Copy link
Member

How do I enable the feature for testing? What setting value did you use for perf testing?

@@ -1176,7 +1176,9 @@ private BuildEventArgs ReadPropertyReassignmentEventArgs()
propertyName,
previousValue,
newValue,
location,
fields.File,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Reader we can't change the logic without also checking the version. Because if we're reading an old binlog, this is going to read corrupt data.

You can add if (version >= 25) ... read new stuff, otherwise leave the current logic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed the reader to read the File, Line and Column separately, but the writer still writes Location as a single string

@@ -567,11 +567,12 @@ private BinaryLogRecordKind Write(CriticalBuildMessageEventArgs e)

private BinaryLogRecordKind Write(PropertyReassignmentEventArgs e)
{
WriteMessageFields(e, writeMessage: false, writeImportance: true);
WriteMessageFields(e, writeMessage: true, writeImportance: true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changing to true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously, the message was provided by logviewer resources.
In this PR I attempted to pass a localized Message from MSBuild

@KirillOsenkov
Copy link
Member

I'm seeing something weird, and it's not because of your PR.

Location for property reassignment is being logged as null, so the property reassignment messages end up looking like this:

image

But with your PR the location is there:
image

I don't understand what's going on.

@KirillOsenkov
Copy link
Member

There are two things I did to investigate the binlog size increase:

  1. use File -> Statistics in the viewer, then right-click on the Statistics node (the last one in the tree) and click Copy children, then diff for an old binlog and new binlog
  2. under Statistics -> Strings, expand and select the only node under Strings, then press Space (this will view all the strings in the text editor) - diff those, I notice a lot of new strings with this change (primarily strings for file, line and column appended) - these shouldn't be added

For diffing, pick a simple console application, and do an incremental build (not clean build), setting MsBuildLogPropertyTracking to the right value. What is the default value for it currently? Why are property reassignment messages even logged when the value is 0 (the current default)?

@KirillOsenkov
Copy link
Member

Ah, I see:

// Either we want to specifically track property reassignments
// or we do not want to track nothing - in which case the prop reassignment is enabled by default.
if ((_settings & PropertyTrackingSetting.PropertyReassignment) == PropertyTrackingSetting.PropertyReassignment ||
(_settings == 0 && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10)))

@KirillOsenkov
Copy link
Member

I'm not quite sure, but I think we might have lost the location for property reassignment with #10102 (FYI @JanKrivanek)

@KirillOsenkov
Copy link
Member

MSBuild 17.12 (the one I use) doesn't log PropertyReassignmentEventArgs, it logs a message, which the viewer than parses, and there is no location there

@KirillOsenkov
Copy link
Member

Wait, no, I'm super confused. The location was only null for properties coming from toolset. For properties coming from XML the location is there and was passed as a string argument (one of 4 args). This is good, we have an opportunity to be better than the current state.

location?.File,
location?.Line ?? 0,
location?.Column ?? 0,
message: ResourceUtilities.GetResourceString("PropertyReassignment"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? I think we can leave the message null.

Even if we needed this, we could call GetResourceString once and cache it, since it never changes, and it's pretty expensive.

location?.File,
location?.Line ?? 0,
location?.Column ?? 0,
ResourceUtilities.GetResourceString("PropertyAssignment"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid getting this string at all.

{
get
{
var formattedSource = File != null ? $"{File} ({LineNumber},{ColumnNumber})" : PropertySource;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want to cache this in case Message gets called multiple times, need to see what other EventArgs classes do when they override Message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could get the string from resources here, since we know what string we want.


return RawMessage;
string formattedLocation = File != null ? $"{File} ({LineNumber},{ColumnNumber})" : Location;
return string.Format(RawMessage, PropertyName, NewValue, PreviousValue, formattedLocation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, look into caching the formatted result and look into getting the resource string here.

@JanKrivanek
Copy link
Member

Wait, no, I'm super confused. The location was only null for properties coming from toolset. For properties coming from XML the location is there and was passed as a string argument (one of 4 args). This is good, we have an opportunity to be better than the current state.

Did we have the location for props comming from toolset before? Or is that regression?

@YuliiaKovalova
Copy link
Member Author

How do I enable the feature for testing? What setting value did you use for perf testing?

please set MsBuildLogPropertyTracking=15

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.

Log how properties are initially assigned
3 participants