Send task-host build process environment as delta
Fixes #14097
Context
Out-of-proc task hosts re-send the same build-invariant data in every TaskHostConfiguration (and echo the environment back in every TaskHostTaskComplete). Two payloads dominate this redundancy on large -mt builds:
- The build process environment (~6 KB), shipped forward in every config and back in every result.
- On solution builds, the
CurrentSolutionConfigurationContentsglobal property — an XML blob describing every project's configuration (~57 KB on OrchardCore) — shipped forward in every config. It is ~99% of the global-properties payload and ~48% of all task-host config bytes.
Both are invariant for the vast majority of tasks, yet re-transmitted in full to connections that already received them.
Changes Made
-
Send the environment as a delta. Under a negotiated wire format (PacketVersion 5) the environment is sent in full only once per task-host connection; subsequent packets whose environment is unchanged carry a 1-byte "identical" marker instead of the full dictionary, on both the forward (config) and return (result) paths. The receiver reconstructs it from the last full environment seen on that connection.
-
Deduplicate the solution configuration blob. Solution (
.sln/.slnx) builds injectCurrentSolutionConfigurationContentsas a global property on every project. It is build-invariant (it describes the solution, not the project), but it is re-serialized into everyTaskHostConfiguration. It cannot simply be dropped — a task may read it at runtime viaIBuildEngine6.GetGlobalProperties()— so the same per-connection delta is applied (PacketVersion 65: the value is carried in its own field, excluded from the global-properties dictionary on the wire (so the large blob is never serialized twice), preceded by a 1-byte Full/Identical marker. It is sent once per connection, then only a marker; the task host reconstructs it from the connection baseline. -
Skip redundant per-task environment apply/restore in the task host when the next task's environment is unchanged from the previous one.
-
Bug fixes:
- Self-clear: feeding the reused (unchanged) environment back into
SetEnvironmentcleared it, because in-mtit was the driver's own backing dictionary. Fixed with a reference-equality guard.
- Self-clear: feeding the reused (unchanged) environment back into
Testing
- Round-trip serialization tests for the new Full/Identical wire forms: environment and
CurrentSolutionConfigurationContentsat PacketVersion 5 -mtend-to-end regression tests: environment observed across consecutive task-host tasks, and an environment change made by one task-host task is observed by the next (verified failing before the aliasing fix, passing after).- Validated end-to-end: full build incl. net35, and OrchardCore.slnx
-mtRebuild succeeds. - Existing task-host test suites pass.
Measurements
Workload: OrchardCore (OrchardCore.slnx), -t:Rebuild -mt — 17,975 task-host task invocations. Serialized payload sizes measured with ThProfile (write-side stream-position deltas; deterministic, single run). Baseline = upstream main; patched = this PR.
| Task-host IPC payload | Baseline | This PR | Saved |
|---|---|---|---|
| Build process environment (forward + return) | 122.0 MB | 0.1 MB | ≈ 122 MB |
CurrentSolutionConfigurationContents (forward) |
647.4 MB | 1.8 MB | ≈ 646 MB |
| Total task-host IPC (config + result) | ≈ 1,548 MB | ≈ 764 MB | ≈ 785 MB (−51%) |
Per direction:
| Field | Baseline | This PR | Reduction |
|---|---|---|---|
TaskHostConfiguration total (forward) |
1,342 MB | 620 MB | −54% |
| ↳ environment | 61.0 MB | 0.1 MB | −99.8% |
↳ CurrentSolutionConfigurationContents |
647.4 MB | 1.8 MB | −99.7% |
| ↳ global properties (incl. the blob) | 653.6 MB | 7.9 MB | −98.8% |
TaskHostTaskComplete total (return) |
206.4 MB | 143.3 MB | −31% (all from the environment) |
The environment was ~4.6% of every config packet and ~29.7% of every result packet; CurrentSolutionConfigurationContents was ~48% of every config packet. After the change each carries only a 1-byte "unchanged" marker once the connection baseline is established. The remaining config payload is dominated by per-task task parameters, which are not invariant and so are not deduplicated.
Wall-clock / overhead
Sending the environment as a delta, deduplicating the solution configuration, and skipping the redundant per-task environment apply/restore did not measurably change total wall-clock time or task-host overhead in my measurements — the IPC savings are below the run-to-run noise floor on my machine. This is an IPC-volume optimization (fewer bytes serialized/transmitted/deserialized), not a critical-path one.
I measured TaskHost overhead on OrchardCore after restore on my machine three times and took the average, using this guide to compute task host overhead. (Note: in this guide all MSBuildMultiThreadableTask parameters were deliberately deleted; I kept them, of course.)
The measurement showed no significant improvement on total time for task and overhead:
Baseline:
Patched version:
| Metric | Before → After | Delta | Surface reading |
|---|---|---|---|
| Total task-host time | 871,916 → 1,008,858 ms | +136,942 ms (+15.7%) | looks like regression |
| Overhead share | 58.6% → 54.4% | −4.2 pp (−7.2% rel.) | looks like improvement |
Both deltas are likely noise (the two metrics point in opposite directions, and execute_ms — task work this change cannot affect — moved by a similar magnitude, indicating machine-load drift rather than a real effect).