fix(managed): index attribute constructor owners once per layout (#1943)

Each CustomAttribute whose constructor is a local MethodDef scanned the
TypeDef table to find the declaring type, so inspect_managed_artifact did
O(attributes x types) row decoding. A 584 KB assembly with 16,000 types
and 16,000 such attributes blocked for about 38 s.

Build a first-match owner index once per metadata layout. Already-owned
list positions are skipped, so overlapping malformed method lists keep
their previous first-match owner in near-linear time. The index is
charged to the decode budget, and a build failure is cached like the
member pointer lookup.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-12 04:09:50 +08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 14935e4d47
commit c2cf7dcb86
2 changed files with 105 additions and 24 deletions
@@ -259,6 +259,35 @@ describe("managed artifact coded indexes", () => {
layout.codedIndexSize("HasCustomAttribute"),
);
});
it("resolves local attribute constructors without rescanning TypeDef rows", () => {
// The owning type follows every empty type. A per-attribute TypeDef scan
// took about 38 s here; the owner index is built once per layout.
const bytes = buildManagedPeFixture({
additionalEmptyTypes: 16_000,
customAttributeRowCount: 16_000,
customAttributeTypeRaw: (1 << 3) | 2,
typeName: "LookupAttribute",
extendsRaw: 0,
methodName: ".ctor",
methodFlags: 0x1886,
methodSignature: Buffer.from([0x20, 0x01, 0x01, 0x0e]),
});
const start = performance.now();
const artifact = inspectManagedArtifactBytes(
bytes,
managedPeFixtureTarget(bytes),
);
expect(performance.now() - start).toBeLessThan(2000);
expect(artifact.coverage).toEqual({ state: "complete", issues: [] });
expect(artifact.attributes).toHaveLength(16_000);
expect(
artifact.attributes.every(
(attribute) => attribute.type_name === "Fixture.LookupAttribute",
),
).toBe(true);
}, 30_000);
});
describe("managed artifact reference inventory", () => {