Skip to content

Avoid LineInfoAnnotation allocations in MetadataFieldConverter JSON parsing - #7056

Merged
zivkan merged 2 commits into
NuGet:devfrom
nareshjo:metadataFieldConverter-JsonLineInfoAllocs
Jan 26, 2026
Merged

zivkan merged 2 commits into
NuGet:devfrom
nareshjo:metadataFieldConverter-JsonLineInfoAllocs

Conversation

@nareshjo

Copy link
Copy Markdown
Contributor

This pull request was generated by the VS Perf Rel AI Agent. Please review this AI-generated PR with extra care! For more information, visit our wiki. Please share feedback with TIP Insights

  • Issue: MetadataFieldConverter.ReadJson() loads the JSON array into a full LINQ-to-JSON DOM (JArray.Load(reader)), which allocates a JValue per element and by default attaches line-info metadata (LineInfoAnnotation) to each token.
    This matches the allocation stack flow showing MetadataFieldConverter.ReadJson → Newtonsoft.Json.Linq.JArray.Load → JContainer.ReadTokenFrom/ReadContentFrom → JToken.SetLineInfo → TypeAllocated!LineInfoAnnotation
nuget.protocol.dll!NuGet.Protocol.MetadataFieldConverter.ReadJson
newtonsoft.json.dll!Newtonsoft.Json.Linq.JArray.Load
newtonsoft.json.dll!Newtonsoft.Json.Linq.JContainer.ReadTokenFrom
newtonsoft.json.dll!Newtonsoft.Json.Linq.JContainer.ReadContentFrom
newtonsoft.json.dll!Newtonsoft.Json.Linq.JToken.SetLineInfo
TypeAllocated!LineInfoAnnotation
  • Issue type: Avoid unneeded line-info allocations while loading JSON

  • Proposed fix: Load the array with line info disabled.
    ReadJson immediately converts the array to a string and doesn’t use token line/column metadata.
    So skipping LineInfoAnnotation reduces unnecessary allocations without affecting functional behavior.

Best practices wiki
See related failure in PRISM
ADO work item

@nareshjo
nareshjo requested a review from a team as a code owner January 15, 2026 16:19
@nareshjo
nareshjo requested review from jeffkl and martinrrm January 15, 2026 16:19
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Jan 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jan 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 30 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@dotnet-policy-service dotnet-policy-service Bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jan 23, 2026
@zivkan
zivkan merged commit 63dbdcb into NuGet:dev Jan 26, 2026
16 checks passed
@nareshjo
nareshjo deleted the metadataFieldConverter-JsonLineInfoAllocs branch January 26, 2026 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants