Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

Fixes #11959 (assuming this is the issue number - please update)

Context

EnsureParameterInitialized concatenates strings on every parameter initialization:

string key = "DisableLogTaskParameter_" + _taskName + "_" + parameter.Name;

This allocates on the hot path during task execution.

Changes Made

TaskFactoryWrapper.cs

  • Added DisableLogTaskParameterKeys and DisableLogTaskParameterItemMetadataKeys dictionaries to PropertyData
  • Precompute lookup keys in PopulatePropertyInfo() during task factory initialization
  • Exposed GetDisableLogTaskParameterKey() and GetDisableLogTaskParameterItemMetadataKey() to retrieve precomputed strings

TaskExecutionHost.cs

  • Replaced string concatenation with dictionary lookups:
// Before: allocates on every call
string key = "DisableLogTaskParameter_" + _taskName + "_" + parameter.Name;

// After: retrieves precomputed string
string key = _taskFactoryWrapper.GetDisableLogTaskParameterKey(parameter.Name);

Testing

  • All TaskExecutionHost and TaskFactory unit tests pass
  • Verified with sample and real-world project builds

Notes

Keys are computed once per task factory and reused across all parameter initializations, eliminating allocations from the hot path.

Original prompt

This section details on the original issue you should resolve

<issue_title>add a lookup table to TaskExecutionHost.cs</issue_title>
<issue_description>During a review discussion for PR that optimizes TaskExecutionHost
We've come to conclusion that it is a step in a good direction, however there is a further improvement to be had: #11959 (comment)

We can skip string key = "DisableLogTaskParameter_" + _taskName + "_" + parameter.Name; which allocates by instead building a lookup table when we have the available set of tasks and parameter names and then fetching the strings from there.

Task:
build said lookup table to lower the allocations on the hot path further.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 16, 2025
@dotnet-policy-service
Copy link
Contributor

Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

Copilot AI changed the title [WIP] Add a lookup table to TaskExecutionHost Add lookup table to TaskExecutionHost to eliminate hot-path allocations Nov 16, 2025
Copilot AI requested a review from JanProvaznik November 16, 2025 22:09
Copilot finished work on behalf of JanProvaznik November 16, 2025 22:09
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.

add a lookup table to TaskExecutionHost.cs

2 participants