Skip to content

Cache oversized string references in the binary logger - #15524

Merged
AlesProkop merged 1 commit into
mainfrom
alesprokop-binlog-cache-draft-pr
Nov 16, 2026
Merged

AlesProkop merged 1 commit into
mainfrom
alesprokop-binlog-cache-draft-pr

Conversation

@AlesProkop

@AlesProkop AlesProkop commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Context

The binary logger repeatedly scans large strings even when the same string instance has already been logged. This PR avoids that repeated work.

Changes

  • Cache references to a few recently used large strings so repeated logging can reuse the existing result.
  • Limit additional retained string data to approximately 1 MiB per writer, leaving larger strings on the existing path.
  • Preserve the serialized output and cover cache eviction and retention limits with regression tests.

Performance

PerfStar: OrchardCore warm incremental MT build with binary logging; medians from five iterations per OS, control run 15979812 versus cache-only run 15982075.

OS Control Cache-only Change
Linux 29.31 s 26.63 s −9.14%
Windows 26.76 s 27.09 s +1.22%

Comparison: Linux · Windows

Preliminary single-pair results: binlog-off medians also drifted (+4.47% Linux, +8.30% Windows), so these do not establish a general speedup; Windows is inconclusive.

Testing

  • Identical candidate previously built successfully; focused logging tests passed on .NET 11 and .NET Framework 4.7.2 (292 passed per host).
  • Full-data replay preserved uncompressed event/import bytes and file sizes on Windows and Linux.
  • No fresh publication-branch build/tests; the broader investigation suite had failures. Fresh CI validation remains necessary.

Independent PerfStar binlog experiment based on 3df416b.

Co-authored-by: Copilot App <[email protected]>
@AlesProkop
AlesProkop marked this pull request as ready for review November 11, 2026 08:26
Copilot AI balanced review requested due to automatic review settings November 11, 2026 08:26

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.

🟢 Approval recommended

No active review issues remain for the bounded large-string cache change.

No open issues 🎉

What changed in this PR

Adds a bounded cache to MSBuild’s binary logger to avoid repeatedly hashing large strings when the same instance is logged, without changing the serialized format.

Changes:

  • Cache up to four large string references, retaining approximately 1 MiB of additional string data per writer.
  • Leave strings above 131,072 characters on the existing path.
  • Add regression tests for serialized-byte equality, cache eviction, and retention limits.
File Description
src/​Build/​Logging/​BinaryLogger/​BuildEventArgsWriter.cs Adds the bounded large-string reference cache and reuses cached record IDs and hashes.
src/​Build.UnitTests/​BuildEventArgsSerialization_Tests.cs Adds byte-equality, eviction round-trip, and retention-budget tests.

Review effort: Balanced

@github-actions github-actions Bot 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.

LGTM — Test Coverage & Completeness. The tests deterministically cover byte-for-byte serialization invariance, direct-mapped cache eviction/readability, the inclusive upper eligibility boundary, oversized exclusion, four-slot capacity, and the retention budget with strong assertions.

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com
  • patchdiff.githubusercontent.com
  • raw.githubusercontent.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"
    - "patchdiff.githubusercontent.com"
    - "raw.githubusercontent.com"

See Network Configuration for more information.

Generated by Expert Code Review (on open) for #15524 · copilot · gpt56 · 630.5 AIC · ⌖ 0.521 AIC · ⊞ 21.7K

@baronfel baronfel 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.

Seems reasonable! A few questions:

  • how many such 'large strings' are found in an existing orchardcore build? could/should we tune the cache size based on that?
  • how did you choose the large string threshold?
  • this only impacts
    • overall build time by reducing binlog processing time overall?
    • memory use of the msbuild process because N indexes are cached for the lifetime of an eventargs writer?
  • this does not impact
    • binlog size because we're still writing the same string reference in the binlog?

@AlesProkop
AlesProkop merged commit 65b0e0a into main Nov 16, 2026
28 checks passed
@AlesProkop
AlesProkop deleted the alesprokop-binlog-cache-draft-pr branch November 16, 2026 15:35
@AlesProkop

Copy link
Copy Markdown
Member Author

@baronfel

  • how many such 'large strings' are found in an existing orchardcore build? could/should we tune the cache size based on that?

In the sampled OC logs, the key case was CurrentSolutionConfigurationContents, which is 80k characters and appears 44k times on each platform.

  • how did you choose the large string threshold?

The lower bound is from an existing small-string cache, and the upper bound is a power of two that keeps approximately 1MiB per writer, so it is more of a reasonable guess.

  • this only impacts

It affects primarily the binary logger serialization CPU: a cache hit skips rescanning the string for its content hash and resues the hash. Memory can increase a little bit, but it is bounded by the size. And right, there is no size reduction in binlog, because it was already stored and written. This only avoids repeated work finding that same ID.

@AlesProkop AlesProkop mentioned this pull request Nov 19, 2026
5 of 16 tasks

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 858a0cb5 Deployed Nov 11, 2026 by AlesProkop via conclusion #1149
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.

3 participants