Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove some overhead from XmlNode.SelectSingleNode#54299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
stephentoub merged 5 commits intodotnet:mainfromstephentoub:selectsinglenode
Jun 17, 2021

Conversation

@stephentoub
Copy link
Member

Using the example fromhttps://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlnode.selectsinglenode?view=net-5.0#System_Xml_XmlNode_SelectSingleNode_System_String_ :

MethodToolchainMeanRatioAllocated
SelectSingleNode\main\CoreRun.exe1,238.4 ns1.002,312 B
SelectSingleNode\pr\CoreRun.exe1,120.9 ns0.912,080 B

buyaa-n reacted with thumbs up emoji
It's currently implemented by delegating to SelectSingleNodes and returning the first one.  While the list is lazily-populated, this still entails creating an `XPathNodeList`, creating a `List<XmlNode>`, storing the enumerated into the list, and then returning the element from the list, which is then thrown away.  With just a few lines, we can cut through all of that.
No need for these to be allocated classes.  They can just live on the stack where they're created.
This shows up on the hot path of parsing the xpath expression.  We can use a span to avoid bounds checking.
NextChar is used by lots of routines to advance to the next character.  We can streamline it to avoid the bounds check when indexing into the string.
The typical case is there isn't any whitespace, so inline that fast check.  This was showing up as a few percentage of a simple scenario.
@ghostghost added the area-System.Xml labelJun 16, 2021
@ghost
Copy link

Tagging subscribers to this area:@buyaa-n,@krwq
See info inarea-owners.md if you want to be subscribed.

Issue Details

Using the example fromhttps://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlnode.selectsinglenode?view=net-5.0#System_Xml_XmlNode_SelectSingleNode_System_String_ :

MethodToolchainMeanRatioAllocated
SelectSingleNode\main\CoreRun.exe1,238.4 ns1.002,312 B
SelectSingleNode\pr\CoreRun.exe1,120.9 ns0.912,080 B
Author:stephentoub
Assignees:-
Labels:

area-System.Xml

Milestone:-

Copy link
Contributor

@buyaa-nbuyaa-n left a comment

Choose a reason for hiding this comment

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

LGTM

@stephentoubstephentoub merged commitbbc3366 intodotnet:mainJun 17, 2021
@stephentoubstephentoub deleted the selectsinglenode branchJune 17, 2021 15:27
@ghostghost locked asresolvedand limited conversation to collaboratorsJul 17, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@krwqkrwqkrwq approved these changes

+1 more reviewer

@buyaa-nbuyaa-nbuyaa-n approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

No open projects

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@stephentoub@krwq@buyaa-n

[8]ページ先頭

©2009-2025 Movatter.jp