- Notifications
You must be signed in to change notification settings - Fork5.2k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
ghost commentedJun 16, 2021
Tagging subscribers to this area:@buyaa-n,@krwq Issue DetailsUsing the example fromhttps://docs.microsoft.com/en-us/dotnet/api/system.xml.xmlnode.selectsinglenode?view=net-5.0#System_Xml_XmlNode_SelectSingleNode_System_String_ :
|
src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathScanner.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
buyaa-n left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathScanner.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathScanner.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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_ :