IL: hold custom attributes in fields rather than a union case - #20287
Open
auduchinok wants to merge 2 commits into
Open
IL: hold custom attributes in fields rather than a union case#20287auduchinok wants to merge 2 commits into
auduchinok wants to merge 2 commits into
Conversation
ILAttributesStored wrapped its state in an ILAttributesStoredRepr union, so every attribute owner allocated a wrapper object on top of the stored object itself: 67,605 Reader wrappers on a 489-reference project, which is exactly the count of owners whose attributes are never read, plus a Given wrapper per owner that is. The reader function is shared per metadata reader per attribute table, so it can be held directly, and ILAttributes is a struct over the array, so rewrapping the array on each read allocates nothing. Holding the array and the reader in fields removes 24 bytes of wrapper per owner and adds 8 for the second field. Retained memory after ParseAndCheckProject drops 0.19-1.30 MB per project (-0.05% to -0.84%) across the measurement suite, and the union type is deleted. ILAttributesStoredRepr was not in the signature file, so there is no API change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
Warning No PR link found in some release notes, please consider adding it.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ILAttributesStoredwrapped its state in a union:so every attribute owner — type def, method, field, property, event, parameter, interface impl —
allocated a wrapper on top of the stored object itself. In a held FSharp.Common analysis 67,605 of 86,667
wrappers are
Reader: 78% of owners never have their attributes read, and the wrapper existed only torecord that.
The change
The reader function is shared per metadata reader per attribute table, so it can be held directly;
ILAttributesis a struct over the array, so rewrapping on each read allocates nothing.CreateGivenstores the array with a shared
noReadersentinel to keep the field non-null. Net per owner: −24 bytes ofwrapper, +8 for the second field.
[<VolatileField>]is kept, and the race is the same benign one asbefore — two threads may both run the reader and store equal results.
No API change:
ILAttributesStoredReprwas internal and not inil.fsi; the members keep theirsignatures and the union type is deleted.
Measured
Against
90767c77e9built in the same session.er-base2is a byte-identical copy of that baseline runthrough the whole harness, so its column is the measurement error; a delta not exceeding both it and the
baseline's own spread is marked not established.
One project held open (mean of 3 fresh processes)
A whole solution held open at once (mean of 2 passes)
What it removes
gcdump of one held FSharp.Common analysis:
Reader67,605 → 1,467,Given19,062 → 0 — 1.99 MB ofwrappers — against
ILAttributesStoredgrowing 2.60 → 3.25 MB for the second field. Net 1.34 MB predicted,1.32 MB measured. The 1,467 remaining
Readerobjects areILSecurityDeclsStored's own union, untouchedhere.