Optimize binary logger metadata serialization - #14929
Open
AlesProkop wants to merge 1 commit into
Open
Conversation
Reuse serialized metadata records for items that share immutable copy-on-write metadata, while preserving fallback and AppDomain behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5f373de-cc23-46fa-bd6f-9ba8c1645411
AlesProkop
temporarily deployed
to
copilot-pat-pool
September 4, 2026 08:38 — with
GitHub Actions
Inactive
AlesProkop
temporarily deployed
to
copilot-pat-pool
September 4, 2026 08:39 — with
GitHub Actions
Inactive
AlesProkop
temporarily deployed
to
copilot-pat-pool
September 4, 2026 08:40 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The optimization is localized, preserves the existing on-wire encoding, and is covered by targeted tests including byte-for-byte equivalence checks.
Pull request overview
This PR optimizes binary logger serialization of task item metadata by memoizing previously-emitted NameValueList record IDs for shared copy-on-write immutable metadata dictionaries, reducing repeated enumeration, unescaping, and hashing work in BuildEventArgsWriter.WriteTaskItemList.
Changes:
- Added a
ConditionalWeakTable<ImmutableDictionary<string,string>, StrongBox<int>>cache to reuseNameValueListrecord IDs for items sharing the same immutable backing metadata dictionary. - Introduced a fast path that enumerates immutable backing metadata directly on cache misses while preserving the existing unescape behavior and metadata ordering contract.
- Added focused unit tests covering shared-metadata reuse, empty-metadata short-circuiting,
TaskItemDatafallback behavior, and byte-for-byte equivalence with the legacy path.
File summaries
| File | Description |
|---|---|
| src/Framework/IMetadataContainer.cs | Documents the escaped-value + ordering contract required for BackingMetadata to be safely consumable for serialization fast paths. |
| src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs | Implements metadata record-id identity caching and updates WriteNameValueList to return the emitted record id for reuse. |
| src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs | Adds regression/compat tests validating reuse, fallbacks, and byte-for-byte serialization equivalence. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #10490
Context
Binary log profiling identified task-item metadata enumeration and hashing in
BuildEventArgsWriter.WriteTaskItemListas the dominant serialization cost. Copy-on-write task items frequently share the same immutable metadata dictionary, but the binary logger previously enumerated, unescaped, and hashed that metadata for every item.Changes Made
NameValueListrecord IDs.TaskItemData, customITaskItemimplementations, and .NET Framework transparent proxies.IMetadataContainer.BackingMetadata.Testing
src/Samples/Dependency/Dependency.csprojwith the bootstrap MSBuild.BuildEventArgsSerializationTests:TaskParameterSerializationReusesSharedBackingMetadata— verifies reuse for sharedUtilities.TaskItemmetadata.TaskParameterSerializationCachesEmptyMetadataAndFallsBackForTaskItemData— verifies empty metadata and theTaskItemDatafallback.TaskParameterSerializationReusesItemDefinitionMetadata— verifies reuse for shared item-definition metadata.TaskParameterBackingMetadataFastPathPreservesSerializedBytes— verifies byte-for-byte equivalence with the legacy fallback path.net11.0; 16 passed, 0 failed onnet472.Notes
ProjectImports=Nonereduced median wall time from 27.20 seconds to 23.20 seconds under MT/server execution./mmeasurements reduced median wall time from 41.44 seconds to 39.79 seconds.