Skip to content

chore: Read the sources a compiled assembly was built from out of its PDB document table - #3275

Merged
hatayama merged 1 commit into
perf/hot-reload-snapshot-capturefrom
perf/hot-reload-pdb-compiled-source-list
Oct 11, 2026
Merged

hatayama merged 1 commit into
perf/hot-reload-snapshot-capturefrom
perf/hot-reload-pdb-compiled-source-list

Conversation

@hatayama

@hatayama hatayama commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Adds the parts that build an assembly's source list from its dll and portable PDB instead of asking Unity's CompilationPipeline.GetAssemblies(), plus a test that cross-checks the two lists on every compiled assembly of this project.
  • Not called from production yet; Phase 2 decides whether the capture uses it.

User Impact

  • None yet. The hot reload source snapshot capture still asks Unity for its assemblies on the main thread after every domain reload. These parts, and the cross-check result below, are the input for deciding whether the capture can stop doing that.

What

  • HotReloadPdbDocumentTable.Read(dll, pdb): matches the PDB to the dll's build by the CodeView GUID (throws InvalidOperationException otherwise), then returns every row of the PDB's document table in table order. Unlike HotReloadPdbDocumentIndex.ReadDocuments, it includes sources without a method body (empty, comment-only or declaration-only files), which no sequence point refers to.
  • HotReloadCompiledSourceMap.FromDocuments(...): maps document urls to the asset paths Unity lists in sourceFiles, plus whether the assembly belongs to an immutable package (decided by the first mapped source, the same rule as ShouldSkipImmutablePackageSources). It handles:
    • ./-relative urls (assemblies compiled with a pathmap) and absolute urls (assemblies without one, and packages outside the project), including Windows drive-letter urls on any platform;
    • embedded packages whose folder differs from the package name, local packages outside the project, and Virtual Players (urls relative to the main project, package resolved under either root);
    • folder-boundary checks (LocalPkg2 is not inside LocalPkg), de-duplication, and dropping generated documents, non-C# documents and project files outside Assets and package roots.
  • HotReloadSnapshotPackageRoots.ReadCurrent(): the registered package roots with the capture's immutability rule (Embedded and Local are editable). Kept separate from ScriptPackageRoots so the type pause points share does not change.
  • HotReloadPdbDocumentIndex.ReadCodeViewGuid and ToHashAlgorithm go from private static to internal static so the table reader reuses them. No other change to existing files.
  • Three fixtures without a method body under Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/.

Cross-check result

  • HotReloadCompiledSourceCrossCheckTests.FromDocuments_MatchesTheSourceFilesUnityListsForEveryCompiledAssembly passes on this repository's development project (Unity 2022.3.62f3, macOS): for all 112 compiled assemblies with sources, a dll and a PDB, the immutability matches ShouldSkipImmutablePackageSources(sourceFiles), and for the editable ones the asset path set equals sourceFiles.
  • Reading all 112 document tables took 85 ms and 88 ms in two runs (files already in the OS cache; measured inside the test with a Stopwatch around Read only).
  • Not checked: Unity 6000.x (whose pathmap use may differ; the map handles both url forms for that reason) and Windows.

Verification

Run one class at a time with uloop run-tests --filter-type class:

  • HotReloadCompiledSourceMapTests: 23 passed (one test per row of the input table; 17 failed against a stub before the implementation).
  • HotReloadPdbDocumentTableTests: 2 passed (both failed against a stub).
  • HotReloadCompiledSourceCrossCheckTests: 2 passed. With the Assets/ mapping disabled as a mutation, both failed and the cross-check listed the 17 Assets-side assemblies whose lists differed.
  • HotReloadPdbDocumentIndexTests (existing): 26 passed after the visibility change.
  • scripts/check-file-length.sh: no file over the limit.

View guided diff

…cument table

Snapshot capture asks Unity for every compilation assembly on the main
thread, which is the one step it cannot move off the main thread. A PDB
already lists every source the compiler was given, so these parts let a
later change build the same list from the dll and PDB instead:

- HotReloadPdbDocumentTable reads every document row, including sources
  without a method body, after matching the PDB to the dll's build.
- HotReloadCompiledSourceMap maps the urls to Unity asset paths for both
  url forms (pathmapped "./" and absolute), packages whose folder differs
  from their name, packages outside the project and Virtual Players.
- HotReloadSnapshotPackageRoots reads the package roots with the same
  immutability rule the capture uses.

A cross-check test compares the result with Unity's sourceFiles for every
compiled assembly of this project. Nothing calls the parts in production
yet.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: hatayama/unity-cli-loop/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9240a451-34fb-4076-a02e-5cececc42338

📥 Commits

Reviewing files that changed from the base of the PR and between 2230f8e and e6f5f72.


⛔ Files ignored due to path filters (11)
  • Assets/Tests/Editor/HotReload/Fixtures.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/CommentOnlySourceFixture.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/EmptySourceFixture.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/InterfaceOnlySourceFixture.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/HotReloadCompiledSourceCrossCheckTests.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/HotReloadCompiledSourceMapTests.cs.meta is excluded by none and included by none
  • Assets/Tests/Editor/HotReload/HotReloadPdbDocumentTableTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadCompiledSourceMap.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadPdbDocumentTable.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadSnapshotPackageRoots.cs.meta is excluded by none and included by none

📒 Files selected for processing (10)
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/CommentOnlySourceFixture.cs
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/EmptySourceFixture.cs
  • Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/InterfaceOnlySourceFixture.cs
  • Assets/Tests/Editor/HotReload/HotReloadCompiledSourceCrossCheckTests.cs
  • Assets/Tests/Editor/HotReload/HotReloadCompiledSourceMapTests.cs
  • Assets/Tests/Editor/HotReload/HotReloadPdbDocumentTableTests.cs
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadCompiledSourceMap.cs
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadPdbDocumentIndex.cs
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadPdbDocumentTable.cs
  • Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadSnapshotPackageRoots.cs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

The change adds portable PDB document-table reading and maps PDB document URLs to Unity asset paths using project and package roots. Editor tests cover PDB identity checks, path mapping and package immutability, and comparisons with Unity’s compiled-source lists.

Changes

PDB Source Mapping

Layer / File(s) Summary
Read PDB document tables
Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadPdbDocumentIndex.cs, Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadPdbDocumentTable.cs, Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/*, Assets/Tests/Editor/HotReload/HotReloadPdbDocumentTableTests.cs
The new reader validates the PDB GUID against the DLL CodeView GUID and returns all document-table rows. Tests cover bodyless source documents and mismatched builds.
Map documents to asset paths
Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadSnapshotPackageRoots.cs, Packages/src/Editor/FirstPartyTools/HotReload/Shared/HotReloadCompiledSourceMap.cs, Assets/Tests/Editor/HotReload/HotReloadCompiledSourceMapTests.cs
The mapper handles project and package paths, duplicate documents, path normalization, and immutability classification. Tests cover these mapping cases.
Cross-check compiled source lists
Assets/Tests/Editor/HotReload/HotReloadCompiledSourceCrossCheckTests.cs
Editor tests compare PDB-derived paths and package classification with Unity’s compiled-source lists, and check for bodyless fixture paths.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Possibly related PRs

  • hatayama/unity-cli-loop#2117: Implements PDB-validated source snapshot capture for hot reload, which uses the same source snapshot workflow.

Merge Risk: ⚪ Minimal · up to e6f5f

The current hot-reload capture behavior is unchanged. No actionable issue identified here prevents merging after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.04% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 53 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: reading compiled-source paths from the PDB document table.
Description check Passed The description directly explains the PDB-based source mapping, package handling, tests, verification results, and current lack of production integration.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hatayama
hatayama merged commit 95d0e62 into perf/hot-reload-snapshot-capture Oct 11, 2026
5 checks passed
@hatayama
hatayama deleted the perf/hot-reload-pdb-compiled-source-list branch October 11, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant