dotnet / dotnet/efcore

Json: improve JsonElement property access caching in deduplication scenarios

Open
#30,100 0 comments 0 reactions 0 assignees View on GitHub
area-json area-perf area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

test: Json_projection_deduplication_with_collection_indexer_in_original

query

```cs
ss.Set().Select(x => new
{
x.Id,
Duplicate1 = x.OwnedCollectionRoot[0].OwnedReferenceBranch,
Original = x.OwnedCollectionRoot[0],
Duplicate2 = x.OwnedCollectionRoot[0].OwnedReferenceBranch.OwnedCollectionLeaf
}).AsNoTracking()
```

in shaper we extract OwnedReferenceBranch twice:

```cs
namelessParameter{3} = namelessParameter{1}.HasValue ? (JsonElement?)namelessParameter{1}.Value.GetProperty("OwnedReferenceBranch") : default(JsonElement?);
namelessParameter{6} = namelessParameter{1}.HasValue ? (JsonElement?)namelessParameter{1}.Value.GetProperty("OwnedReferenceBranch") : default(JsonElement?);
namelessParameter{7} = namelessParameter{6}.HasValue ? (JsonElement?)namelessParameter{6}.Value.GetProperty("OwnedCollectionLeaf") : default(JsonElement?);
```

we could cache at every step and re-use instead. Would need to key off root JsonElement + additional path, which might be bit annoying.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.