-
Notifications
You must be signed in to change notification settings - Fork 89
Reduce deserialization allocations #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f4e0354
85441e1
8f107e0
0e0c2e1
d44ac2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,9 @@ internal class LazyMetadataWrapper : ExportProvider.IMetadataDictionary | |
| /// The underlying metadata, which may be partially translated since value translation may choose | ||
| /// to persist the translated result. | ||
| /// </summary> | ||
| protected ImmutableDictionary<string, object?> underlyingMetadata; | ||
| protected Dictionary<string, object?> underlyingMetadata; | ||
|
|
||
| internal LazyMetadataWrapper(ImmutableDictionary<string, object?> metadata, Direction direction, Resolver resolver) | ||
| internal LazyMetadataWrapper(Dictionary<string, object?> metadata, Direction direction, Resolver resolver) | ||
| { | ||
| Requires.NotNull(metadata, nameof(metadata)); | ||
| Requires.NotNull(resolver, nameof(resolver)); | ||
|
|
@@ -253,7 +253,7 @@ internal static bool TryGetLoadSafeValueTypeRef(IReadOnlyDictionary<string, obje | |
|
|
||
| protected virtual LazyMetadataWrapper Clone(LazyMetadataWrapper oldVersion, IReadOnlyDictionary<string, object?> newMetadata) | ||
| { | ||
| return new LazyMetadataWrapper(newMetadata.ToImmutableDictionary(), oldVersion.direction, this.resolver); | ||
| return new LazyMetadataWrapper(newMetadata.ToDictionary(), oldVersion.direction, this.resolver); | ||
| } | ||
|
|
||
| protected object? SubstituteValueIfRequired(string key, object? value) | ||
|
|
@@ -265,13 +265,13 @@ protected virtual LazyMetadataWrapper Clone(LazyMetadataWrapper oldVersion, IRea | |
| return null; | ||
| } | ||
|
|
||
| value = this.SubstituteValueIfRequired(value); | ||
|
|
||
| // Update our metadata dictionary with the substitution to avoid | ||
| // the translation costs next time. | ||
| this.underlyingMetadata = this.underlyingMetadata.SetItem(key, value); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this no longer applicable?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who are you asking? I see a code comment below that seems to justify it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It added this comment after I asked this. :) I could not get it to resolve the question. |
||
|
|
||
| return value; | ||
| // Note: we intentionally do NOT write the substituted value back into the dictionary. | ||
| // The old ImmutableDictionary-backed implementation called SetItem here, which was | ||
| // structurally thread-safe (it returned a new dictionary and assigned the reference | ||
| // atomically). With Dictionary, concurrent writes would corrupt the internal state. | ||
| // The substitution cost without caching is negligible: TypeRef.Resolve() caches its | ||
| // result in a field, and Enum.ToObject is trivial. | ||
| return this.SubstituteValueIfRequired(value); | ||
| } | ||
|
|
||
| protected virtual object SubstituteValueIfRequired(object value) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.