Skip to content

[bgen] Replace XPath lookups with Dictionary in DocumentationManager#25521

Merged
rolfbjarne merged 1 commit into
mainfrom
dev/rolf/bgen-perf-xpath-lookups
May 27, 2026
Merged

[bgen] Replace XPath lookups with Dictionary in DocumentationManager#25521
rolfbjarne merged 1 commit into
mainfrom
dev/rolf/bgen-perf-xpath-lookups

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

@rolfbjarne rolfbjarne commented May 26, 2026

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).

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>
Copilot AI review requested due to automatic review settings May 26, 2026 06:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 in DocumentationManager’s constructor from /doc/members/member[@name].
  • Replace SelectSingleNode(...) calls in TryGetDocumentation with memberLookup.TryGetValue(...).

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #338cab0] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 338cab0e4a1250e58221961b7c9cc0697c9703e8 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #338cab0] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 338cab0e4a1250e58221961b7c9cc0697c9703e8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 338cab0e4a1250e58221961b7c9cc0697c9703e8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #338cab0] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 338cab0e4a1250e58221961b7c9cc0697c9703e8 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne enabled auto-merge (squash) May 27, 2026 06:08
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [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
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. [attempt 3] Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 18 tests passed. [attempt 4] Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 18 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 338cab0e4a1250e58221961b7c9cc0697c9703e8 [PR build]

@rolfbjarne rolfbjarne merged commit ca43e4a into main May 27, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants