Improve notification filter performance#15610
Conversation
|
@lahma I deleted |
lahma
left a comment
There was a problem hiding this comment.
I know it's a closed PR, just adding couple thoughts...
| // This is necessary as long as there will be string-based comparisons | ||
| // and the need of NotifyEntryComparer | ||
|
|
||
| var cache = _cache; |
There was a problem hiding this comment.
I guess nothing here prevents from Message changing and cache being invalid, private setter for properties (or being get-only) would make a different in API promises
| try | ||
| { | ||
| var protector = _dataProtectionProvider.CreateProtector(nameof(NotifyFilter)); | ||
| var signed = protector.Protect(JConvert.SerializeObject(notifyEntries, _settings)); |
There was a problem hiding this comment.
Commenting here as I cannot comment on existing code...
_existingEntries = messageEntries.Concat(_existingEntries).Distinct(new NotifyEntryComparer(_htmlEncoder)).ToArray();
Have I ever told that I don't like LINQ 😉 Could probably use HashSet directly and also ideally if possible, NotifyEntryComparer.Default (internal static readonly) if the serializer reference equals some known default, maybe internal NotifyEntryComparer.Create() could check such a thing and either create a new instance or use a default one
After the move to STJ some metrics went up. This fixed the lock contentions and large object heaps. Plus some other GC stats are also better. The creation of
JsonSerializerOptionuses a weak reference and locks internally so they shouldn't be created too often. TheNotifyFilterwas created then eagerly while not necessary. Now it's only on demand with some extra caching.