Skip to content

Speed up publicization by patching metadata in place - #232

Merged
krafs merged 1 commit into
mainfrom
perf/in-place-metadata-patch
Jul 26, 2026
Merged

Speed up publicization by patching metadata in place#232
krafs merged 1 commit into
mainfrom
perf/in-place-metadata-patch

Conversation

@krafs

@krafs krafs commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Publicization only flips visibility bits in the fixed-width Flags columns of the TypeDef, Field and Method tables, so the output can be produced by patching a copy of the input rather than having dnlib rebuild the entire metadata.

Measured on a 7.1 MB assembly, the write phase drops from ~1580 ms to ~5 ms, taking the whole cache-miss task from ~1.9 s to ~0.36 s. Cache hits are unaffected — they already skip the write.

Unpatchable layouts fall back to the existing dnlib writer: uncompressed/ENC metadata (#- heap, where deleted rows make row offsets unsafe to compute from rid), an unexpected Flags column name or width, or table extents past the end of the file. Each logs its reason.

Verified beyond the existing suites by diffing against dnlib's own output across three assemblies (7.1 MB / 5.1 MB / 1.1 MB): every member's flags match exactly, and Roslyn loads each patched image as a metadata reference with no diagnostics.

Two known gaps, tracked on the board rather than fixed here:

  • The PE checksum is left stale (dnlib recomputes it). No loader in the test matrix cares, but it is a behavior difference.
  • Strong-named inputs are unverified. The signature is already invalidated by today's dnlib rewrite, so this is most likely parity, but it has not been demonstrated.

Publicization only flips visibility bits in the fixed-width Flags columns
of the TypeDef, Field and Method tables, so the output can be produced by
patching a copy of the input instead of having dnlib rebuild the whole
metadata. Measured on a 7 MB assembly the write phase drops from ~1600ms
to ~5ms, taking the cache-miss task from ~1.9s to ~0.36s.

Unpatchable layouts (ENC/uncompressed metadata, unexpected column shape)
fall back to the dnlib writer.
@krafs
krafs marked this pull request as ready for review July 26, 2026 13:01
@krafs
krafs merged commit 466e351 into main Jul 26, 2026
10 checks passed
@krafs
krafs deleted the perf/in-place-metadata-patch branch July 26, 2026 13:01
@krafs krafs changed the title Patch metadata in place when writing publicized assemblies Speed up publicization by patching metadata in place Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant