[bgen] Replace XPath lookups with Dictionary in DocumentationManager#25521
Conversation
DocumentationManager.TryGetDocumentation was calling
doc.SelectSingleNode("/doc/members/member[@name='...']") for every
member (~30K calls for tvOS). Each XPath query traverses the entire XML
DOM, making this O(n*m) where n=members queried and m=total members.
Replace with a Dictionary<string, XmlNode> built once at construction
time, giving O(1) lookups thereafter.
Performance (tvOS, wall clock time):
- Before: 270s, peak RSS 363MB
- After: 28s, peak RSS 358MB
- Speedup: 9.6x (242s saved)
Generated code: verified identical (git diff = empty).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR optimizes DocumentationManager.TryGetDocumentation in the bgen tool by replacing repeated per-member XPath lookups against the XML documentation DOM with a precomputed Dictionary<string, XmlNode> for constant-time member resolution. This improves bgen’s documentation lookup performance significantly while keeping generated output unchanged.
Changes:
- Build a
Dictionary<string, XmlNode>once inDocumentationManager’s constructor from/doc/members/member[@name]. - Replace
SelectSingleNode(...)calls inTryGetDocumentationwithmemberLookup.TryGetValue(...).
✅ [PR Build #338cab0] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #338cab0] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [PR Build #338cab0] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #338cab0] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 183 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
DocumentationManager.TryGetDocumentation was calling
doc.SelectSingleNode("/doc/members/member[@name='...']")for every member (~30K calls for tvOS). Each XPath query traverses the entire XML DOM, making this O(n*m) where n=members queried and m=total members.Replace with a
Dictionary<string, XmlNode>built once at construction time, giving O(1) lookups thereafter.Performance (tvOS, wall clock time):
Generated code: verified identical (git diff = empty).