Skip to content

Commit 3a6820b

Browse files
committed
Used MaybeCompatible for AttributeDictionary constructor threshold
The `AttributeDictionary` constructor (#99) adds some overhead to mapping operations if there aren't enough mapped attributes. To mitigate this, a threshold was previously established of five or more attributes or convertible properties (2e157e5). This was meant to account for the fact that we expect upwards of five compatible properties on the base `TopicViewModel`. With the introduction of the new `MaybeCompatible` property (6662e18, 359eaae, 1e2dc53), however, we can use a more intelligent threshold by only evaluating non-compatible properties. In practice, some compatible properties will _still_ get mapped by the `AttributeDictionary` handling and, thus, potentially benefit from this (e.g., `View`, `IsHidden`). Mapping those will be comparatively fast, however, since they're compatible properties, so measuring off of the incompatible members remains a useful heuristic.
1 parent b0ba64d commit 3a6820b

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ public TopicMappingService(ITopicRepository topicRepository, ITypeLookupService
196196
if (parameters.Count is 1 && parameters[0].Type == typeof(AttributeDictionary)) {
197197

198198
// This strategy is only performant if there are quite a several scalar properties and they are well-covered by the
199-
// attributes. As a fast heuristic to evaluate this, we expect five or more attributes and properties. In practice, this
200-
// should be benefitial with any more than mapped attributes, but we also expect that most topics will have 2-3 excluded
201-
// or unmapped attributes (e.g., Title, LastModified) and that models will have five or properties that aren't mapped to
202-
// attributes (e.g., Id, Key, WebPath). This doesn't guarantee that the attributes map to the properties, but a more
203-
// accurate evaluation undermines the performance benefits of this optimization.
204-
if (topic.Attributes.Count >= 5 && properties.Count(p => p.IsConvertible) >= 5) {
199+
// attributes. As a fast heuristic to evaluate this, we expect five or more attributes and three or more compatible
200+
// properties. In practice, this should be benefitial with any more than mapped attributes, but we also expect that most
201+
// topics will have 2-3 excluded or unmapped attributes (e.g., Title, LastModified). With models, we can be a bit more
202+
// intelligent, by excluding any members that are likely compatible with Topic properties, thus exluding e.g., Id, Key,
203+
// WebPath, etc. This doesn't guarantee that the attributes map to the properties, but a more accurate evaluation would
204+
// undermine the performance benefits of this optimization.
205+
if (topic.Attributes.Count >= 5 && properties.Count(p => !p.MaybeCompatible) >= 3) {
205206
var attributes = topic.Attributes.AsAttributeDictionary(true);
206207
arguments[0] = attributes;
207208
attributeArguments = attributes;

0 commit comments

Comments
 (0)