Skip to content

Conversation

@hamarb123
Copy link
Contributor

See https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs#L181-L193 - it's intended to be mutated on Get so that it can cache the XNamespace object - the fields being marked readonly completely block all caching.

@ghost ghost added the area-System.Xml label Apr 17, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 17, 2024
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.

private readonly NamespaceCache _eCache;
private readonly NamespaceCache _aCache;
private NamespaceCache _eCache;
private NamespaceCache _aCache;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this occurred as part of moving these from being locals to being fields as part of d88ba5b#diff-b2b608017bdbacf5e4484368d6e1fcb03a9ea3b68f4aece41da253f72826acf9R908. Would they be better again as locals? I'm not sure why they were moved to be fields, but they're increasing the size of the ContentReader object by being here.
cc: @krwq

@krwq
Copy link
Member

krwq commented May 20, 2024

@hamarb123 please see @stephentoub's comments

@hamarb123
Copy link
Contributor Author

hamarb123 commented May 20, 2024

@hamarb123 please see @stephentoub's comments

So, we want to move them to locals and pass them by reference to the methods?
Otherwise, they're just going to be called once making the caching pointless (like it is currently due to readonly) as all the current uses I looked at only call it once per method (of _eCache at least).

@hamarb123
Copy link
Contributor Author

Except that won't work for the async methods... since it's a ref

@hamarb123
Copy link
Contributor Author

hamarb123 commented May 20, 2024

So, it seems like previously all the stuff was done in ReadContentFrom - but now it's done in multiple sub-funtions, seemingly to support async. Previously the cache was declared in ReadContentFrom and used throughout the whole invocation. It seems like the same cache is still supposed to be used throughout the whole iteration, except that it was marked readonly (which accidentally broke the caching) - but it was moved to be a field, not a local, due to being easier to that being easier to work with async presumably. It looks like we could make it a local - for the sync version/s that would save a few bytes of allocation, and for the async version/s it would move the allocation - and just pass it by byref to the sync method that uses it (I assume we can do this in async?).

Please confirm the preferred approach @krwq @stephentoub

@hamarb123
Copy link
Contributor Author

/ping @krwq @stephentoub ^

@stephentoub stephentoub added this to the 9.0.0 milestone Jul 9, 2024
@stephentoub
Copy link
Member

Ok, let's keep them as fields for now but revisit subsequently.

@stephentoub stephentoub merged commit 4555974 into dotnet:main Jul 22, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Xml community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants