Skip to content

Aggregate RAR search diagnostics in binary logs - #14599

Merged
baronfel merged 11 commits into
mainfrom
baronfel-analyze-binlog-size
Sep 17, 2026
Merged

baronfel merged 11 commits into
mainfrom
baronfel-analyze-binlog-size

Conversation

@baronfel

@baronfel baronfel commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Context

ResolveAssemblyReference (RAR) currently writes one BuildMessageEventArgs for each rejected assembly candidate. Large builds can contain millions of these events.

The analyzed 823.6 MiB binlog contained approximately 19.6 million RAR messages. This change replaces 14,731,030 of them:

  • 12,963,982 candidate-rejection messages
  • 1,296,736 missing-candidate messages
  • 470,312 search-path messages

Those messages represent 676,781 reconstructable references, so the new design writes at most 676,781 aggregate events: at least 14,054,249 fewer records, a 95.4% reduction and at least a 21.8:1 collapse ratio. The exact aggregate count cannot be reconstructed from the old events because they do not contain a durable reference correlation key.

The projected compressed binlog size is approximately 767 MiB, with a range of 750–780 MiB. This is a reduction of approximately 45–75 MiB (5–9%), with a central estimate of 56 MiB (6.8%). The estimate is based on the final structured serializer, including invariant resource lookup, omission of serialized message formats, and lossless repeated-context compression. It excludes RestoreTaskEx, Tsc, and RAR conflict-list output.

The record-count reduction is much larger than the byte reduction because the legacy messages already serialize lazy format strings and arguments through the binlog string table. Candidate paths, assembly identities, and rejection results remain in the structured payload; the byte savings primarily come from removing repeated event framing, timestamps, build contexts, and argument references.

Implementation

  • Adds AssemblyResolutionSearchTraceEventArgs, a structured Framework event representing all rejected candidates for one reference.
  • Stores the requested identity, target processor architecture, and structured search attempts; repeated search-path context is compressed losslessly.
  • Serializes only the structured fields. The binary logger uses writeMessage: false, so neither the rendered multiline message nor its resource formats are written to the binlog.
  • Moves the nine affected RAR resources and all 13 existing translation sets from Tasks to Framework so the event owns its presentation strings.
  • Keeps Message lazy, cached, and formatted with CultureInfo.InvariantCulture for deterministic binlog replay and third-party logger behavior.
  • Adds FormatMessage(CultureInfo) for localized presentation. Built-in Console and Terminal logger paths use CurrentUICulture when they display the event, after their existing importance/verbosity filtering.
  • Supports node transport, task-host transport, out-of-process RAR nodes, and binary-log replay while restoring ProjectFile correctly.
  • Increases the binary-log format version to 28 for the new record kind.

Compatibility

The aggregate multiline message preserves the candidate details from the individual messages. Per-event timestamps, target names, task identifiers, and similar logger decorations are now emitted once per reference instead of once per candidate.

MSBUILDDISABLEFEATURESFROMVERSION=18.12 restores the legacy individual candidate messages. Both paths use the same Framework-owned resources, preventing their text and translations from drifting. Warning and error behavior does not change.

External loggers that read Message receive deterministic invariant text. Loggers that want localized presentation can call FormatMessage(CultureInfo).

Older forward-compatible readers skip the new length-prefixed event and continue reading the remainder of the binlog; they do not display the aggregate search trace.

Performance characteristics

The reduction primarily comes from replacing millions of event records with one structured record per reference, not from eagerly rendering or deduplicating a large composite string.

Message rendering remains lazy. Capture and binary serialization do not materialize Message; they serialize the raw structured fields directly. Culture-specific output is materialized only when a displaying logger requests it and is cached per event to avoid duplicate rendering across built-in loggers.

The final serializer reduces the steady-state uncompressed affected stream by approximately 57–71% across representative traces containing 2–512 attempts. A gzip model containing realistic build contexts and project-file fields reduced the affected compressed stream by approximately 57–71% for representative traces containing 32–512 attempts. Scaling the observed compressed savings per replaced record to the measured 14,731,030 affected records produces the approximately 56 MiB central estimate above.

Capture allocations improve by 49–62% across 2–512 attempts per reference, with an 11.5% end-to-end improvement at 116 attempts. The fixed event schema has overhead for very small traces, while larger traces benefit from component-level string deduplication and repeated-context compression.

Testing

Focused Build and Tasks tests cover:

  • invariant and localized formatting for every result kind
  • Console and Terminal logger localization
  • binary serialization and replay
  • node-packet and task-host transport
  • multi-node logging
  • ChangeWave opt-out behavior
  • AssemblyFoldersEx and repeated-context handling

The affected Debug and Release tests pass on both net472 and net11.0.

Design decision

The event does not split a single reference trace into chunks. A reference is the natural diagnostic unit, and observed chatty references contain hundreds of attempts.

@baronfel
baronfel marked this pull request as ready for review August 27, 2026 19:37
Copilot AI lite review requested due to automatic review settings August 27, 2026 19:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces binary log size for large builds by replacing per-candidate RAR rejection BuildMessageEventArgs spam with a single structured, per-reference search-trace event that can be deduplicated in the binlog string table. It introduces a new AssemblyResolutionSearchTraceEventArgs payload, wires it through node/taskhost/out-of-proc RAR transports, and bumps the binlog format version to 28 while providing a ChangeWave opt-out (MSBUILDDISABLEFEATURESFROMVERSION=18.11).

Changes:

  • Add AssemblyResolutionSearchTraceEventArgs (+ supporting attempt/result/types) to represent RAR search diagnostics as structured data.
  • Update RAR to emit a single aggregated event per reference (ChangeWave-gated), plus update node packet plumbing and out-of-proc client handling for the new event type.
  • Extend binary logger reader/writer with a new record kind to serialize/deserialize the structured event (binlog format v28), and add focused unit tests.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/UnitTests.Shared/MockEngine.cs Capture BuildMessageEventArgs instances for assertions in tests.
src/Tasks/AssemblyDependency/ResolveAssemblyReference.cs Emit aggregated per-reference search trace events (Wave18_11) and factor AssemblyFoldersEx tracking.
src/Tasks/AssemblyDependency/Node/OutOfProcRarClient.cs Forward the new search-trace event type as a message event.
src/Tasks.UnitTests/AssemblyDependency/AssemblyResolutionSearchLogging_Tests.cs Validate aggregation behavior, opt-out behavior, and legacy-text equivalence.
src/Shared/LogMessagePacketBase.cs Add a new LoggingEventType and instantiate/identify the new event for node transport.
src/Framework/AssemblyResolutionSearchTraceEventArgs.cs Define the new public event args type, attempt/result types, and node-transport serialization.
src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs Add serialization for the new binlog record kind (deduplicated strings, no rendered message).
src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs Add deserialization for the new binlog record kind.
src/Build/Logging/BinaryLogger/BinaryLogRecordKind.cs Add AssemblyResolutionSearchTrace record kind.
src/Build/Logging/BinaryLogger/BinaryLogger.cs Bump binlog file format version to 28 and document the new record kind.
src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs Add round-trip coverage for the new event args type.
src/Build.UnitTests/BackEnd/TaskHost_Tests.cs Validate multi-node taskhost logging of the new event type.
src/Build.UnitTests/BackEnd/NodePackets_Tests.cs Validate packet type mapping and translation for the new event type.
documentation/wiki/ChangeWaves.md Document the Wave18_11 behavior change and opt-out knob.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@baronfel
baronfel force-pushed the baronfel-analyze-binlog-size branch from e4fe50f to d2e3c6b Compare August 27, 2026 19:47

@rainersigwald rainersigwald left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm afraid I have a big scary question: does this actually save binlog size/string duplication? It looks like we had individual format strings for the different messages, so they should have been serialized as formatstring + stringified arg array. This is cleaner structuring, but does it reduce the number of unique strings?

@baronfel

Copy link
Copy Markdown
Member Author

@rainersigwald I dug way more into this and you're right that the lazy format+args pattern is working today. In the big binlog we've been investigating, the 19 million+ RAR-specific messages are actually reusing the same 18 format strings, plus another 74k unique deduplicated strings that are used correctly in 47 million parameter references.

So from a 'are we correctly storing deduped strings' perspective this is working. But it still carries a cost to store each of them. Copilot estimates a raw size of 46 bytes/message on average, which compressed down to 6 or 7 bytes in the final gzip stream. Aggregated across the 19 million messages that's still ~114MB of space. So reducing the count of messages down to ~600k or so would be 3 or 4 MB of space by comparison.

The sheer number of messages/records then becomes the next thing to tackle. It takes time to process those 19m RAR-responsible messages, which is harder for me to measure directly but likely still nontrivial.

Comment thread documentation/wiki/ChangeWaves.md Resolved
Comment thread src/Shared/LogMessagePacketBase.cs Resolved
@AlesProkop

Copy link
Copy Markdown
Member

Measured with the PerfStar RarSearchStress scenario: 4,096 references × 32 rejected paths, three measured iterations, Windows/Linux, normal and /mt.

Comparing the serialization-only run 15290127 with #14599+#14601 15290128, median search binlogs were 35.35–37.05% smaller: approximately 1.90–1.91 MB → 1.20–1.23 MB. Replay confirmed 131,072 legacy rejected-candidate messages → 4,096 structured traces containing the same 131,072 attempts.

@AlesProkop AlesProkop left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM after you solve the merge conflicts.

@baronfel
baronfel force-pushed the baronfel-analyze-binlog-size branch from a68a6bf to af99e59 Compare September 14, 2026 17:10
@baronfel

Copy link
Copy Markdown
Member Author

@AlesProkop ok, rebased and resolved the conflicts!

baronfel pushed a commit that referenced this pull request Sep 14, 2026
## Learning atom

- **What:** Refined the existing "Adding New Build Event Types" guidance
in `.github/skills/maintaining-binary-log-compatibility/SKILL.md` to
require tracing new events through every dispatcher and transport,
including task-host forwarding, while preserving non-fatal handling for
unknown event types.
- **Why:** Review of #14599 found a newly serialized event missing from
`TaskHostTask.HandleLoggedMessage`; review of #14601 found unsupported
logging events could become fatal in a forwarding path. Both are
instances of serialization being updated without validating the complete
event route.
- **Deduplication:** Existing atoms cover serialization/replay round
trips and forwarding completeness separately, but none connects new
event types to every forwarding/dispatch path or calls out preserving
unknown-event behavior.

## Reviewers (core MSBuild team)
Suggested reviewers — core-team members who discussed this pattern
(please assign): ``@dotnet/kitten``

> [!WARNING]
> <details>
> <summary>Firewall blocked 1 domain</summary>
>
> The following domain was blocked by the firewall during workflow
execution:
>
> - `github.com`
>
> To allow these domains, add them to the `network.allowed` list in your
workflow frontmatter:
>
> ```yaml
> network:
>   allowed:
>     - defaults
>     - "github.com"
> ```
>
> See [Network
Configuration](https://github.github.com/gh-aw/reference/network/) for
more information.
>
> </details>

> Generated by [Dreaming (learning atoms
curation)](https://github.com/dotnet/msbuild/actions/runs/34888369620) ·
copilot · gpt56 · 85.9 AIC · ⌖ 9.11 AIC · ⊞ 24.2K ·
[◷](https://github.com/search?q=repo%3Adotnet%2Fmsbuild+%22gh-aw-workflow-id%3A+dreaming.agent%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: Dreaming (learning atoms curation), engine:
copilot, model: gpt-5.6-sol, id: 34888369620, workflow_id:
dreaming.agent, run:
https://github.com/dotnet/msbuild/actions/runs/34888369620 -->

<!-- gh-aw-workflow-id: dreaming.agent -->
<!-- gh-aw-workflow-call-id: dotnet/msbuild/dreaming.agent -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <[email protected]>
@baronfel
baronfel force-pushed the baronfel-analyze-binlog-size branch from af99e59 to dffcf92 Compare September 15, 2026 15:30
Replace per-candidate rejected assembly messages with one structured search trace per reference behind ChangeWave 18.11. Preserve legacy rendering while deduplicating trace components in binary logs and supporting node transport.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b1c8b059-4e8b-4aec-8862-36f474eb2061
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b1c8b059-4e8b-4aec-8862-36f474eb2061
Only capture candidate assembly identities for fusion-name mismatch diagnostics, avoiding unnecessary formatting and serialization for other search outcomes.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Reuse RAR's existing localized resource cache and simplify lazy message formatting without changing serialization or payload behavior.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Move the aggregation gate to ChangeWave 18.12, preserve ProjectFile during replay, and forward structured traces from task hosts. Reduce node and binlog payloads by omitting unused formats and repeated attempt context.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Remove localized message formats from node and binlog serialization. Render aggregate diagnostics lazily from invariant-English templates and retain localized legacy messages behind the change-wave opt-out.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Move the candidate-search resources and translations into Framework, keep the default event message invariant, and let built-in display loggers format with the current UI culture without bloating serialized events.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Adapt the structured RAR TaskHost test to the current node-reuse constructor contract and remove the superseded duplicate ChangeWave entry.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b1c8b059-4e8b-4aec-8862-36f474eb2061
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 80b5a09d-d02d-49cd-9a4c-a7f99397bc1d
@baronfel
baronfel force-pushed the baronfel-analyze-binlog-size branch from bdc3608 to 49fb6bc Compare September 16, 2026 18:39
@baronfel
baronfel merged commit 31d409e into main Sep 17, 2026
14 checks passed
@baronfel
baronfel deleted the baronfel-analyze-binlog-size branch September 17, 2026 14:59
baronfel added a commit that referenced this pull request Sep 17, 2026
## Stack dependency

This draft PR depends on #14599 and targets its
`baronfel-analyze-binlog-size` branch. PR #14599 introduces structured
RAR search-trace events and binary-log format 28. Review and merge
#14599 first.

This PR also uses format 28 because both record types are unshipped and
their length-prefixed records remain forward-skippable.

## Motivation

RAR emitted 2,126 conflict dependency-list messages in the analyzed
823.6 MiB binary log. Those messages contained 992,063,604 characters
(about 946 MiB of uncompressed text).

The structured model contains 1,949 unique strings and 13,560,767 wire
bytes. In the category-specific measurement, gzip size decreased from
49,133,718 bytes to 1,281,821 bytes: a 45.6 MiB (97.4%) reduction for
this category. Whole-log savings remain workload-dependent.

## Changes

- Add structured events for low-importance conflict details and
aggregated MSB3277 warnings.
- Transport only structured conflict fields. Do not transport rendered
messages or localized format strings.
- Lazily render `BuildEventArgs.Message` in invariant English for stable
IPC and binary-log replay.
- Expose `FormatMessage(CultureInfo)` on each structured conflict event
so consumers can render another culture when needed.
- Cache resource formats once per culture and cache the latest localized
message per event. Multiple built-in loggers using the same event and
culture reuse the same string.
- Re-localize accepted events in the console, parallel console,
terminal, forwarding terminal, and warning-policy paths using
`CurrentUICulture`. Importance filtering still occurs before rendering.
- Preserve MSB3277 fields and warning promotion, event boundaries,
escaped includes, `ProjectFile`, task-node locations, help keywords, and
`OutputUnresolvedAssemblyConflicts` metadata.
- Support node packets, multi-node task-host forwarding, and
out-of-process RAR transport. Unknown future task-host event types
remain nonfatal.
- Gate the structured conflict event-type change behind ChangeWave
18.12. Disabling the wave restores the legacy localized plain-text
events.

## Compatibility and incremental payload impact

Removing the nine conflict format strings saves 549 bytes per warning
event and 221 bytes per dependency-detail event on IPC. At 1,000 /
100,000 / 100,000,000 events, that is:

| Event | 1,000 | 100,000 | 100,000,000 |
|---|---:|---:|---:|
| Dependency detail | 221 KB | 22.1 MB | 22.1 GB |
| Warning | 549 KB | 54.9 MB | 54.9 GB |

In raw binlogs, string-table deduplication makes the incremental savings
smaller: approximately 8 bytes per detail event and 18 bytes per warning
event, plus about 225 or 558 one-time bytes for the corresponding format
strings. Repeated-reference savings are therefore approximately 8 KB /
0.8 MB / 0.8 GB for detail events and 18 KB / 1.8 MB / 1.8 GB for
warnings at the same scales. Compressed-binlog savings are smaller
because repeated indices compress well.

Filtered events perform no rendering work. Invariant output renders once
and caches in `Message`; non-invariant output performs one
resource-based render per accepted event/culture and caches the result.

## Validation

- Full Debug build completed with 0 warnings and 0 errors (`60.binlog`).
- 52 focused conflict and search-trace tests passed across `net11.0` and
`net472`, with 0 failures and 0 skips.
- Bootstrap build of `src\Samples\Dependency\Dependency.csproj`
completed with 0 warnings and 0 errors (`61.binlog`).
- Coverage includes invariant laziness, French console/terminal
rendering, per-culture cache reuse, serialization, task-host forwarding,
ChangeWave behavior, warning policy, metadata, and large structured
events.

---------

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: aa22c3ca-3e39-4cf7-9fd7-666cc172d93d
Copilot-Session: 555d1cfc-988c-49d3-b17f-81c8593ece36
@AR-May AR-May mentioned this pull request Sep 22, 2026
57 of 69 tasks
KirillOsenkov pushed a commit to KirillOsenkov/MSBuildStructuredLog that referenced this pull request Oct 27, 2026
dotnet/msbuild#14599 and #14601 replaced ResolveAssemblyReference's plain-text
diagnostics with three structured record kinds (AssemblyResolutionSearchTrace,
AssemblyConflictDependencyDetails, AssemblyConflictWarning), currently reachable
via ChangeWave 18.12 / VS Insiders builds. Without this, those records collapse
into one generic "Skipped some data unknown to this version of Viewer" warning.

Adds reader support only, matching the precedent set for MSBuildServerLifecycle
(the last new record kind, added for format v27): no BuildEventArgsWriter path,
so these events won't survive a redact/merge round-trip through this project.
Local shim classes live in the Microsoft.Build.Framework namespace since this
project pins that package well below the version that defines the real types.

Rendering reuses existing node types (Parameter/Item for the search trace,
Warning/Folder/Item for conflicts - the structured-data counterpart of
ItemGroupParser.ParseThereWasAConflict's legacy text parsing) rather than
reproducing the old primary/dependency/unified categorization.

See #968.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

5 participants