Query: Be smart about what to store in variables for shaper
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
Research direction
Start by reading related issues #21334 and #21335, then trace how ProjectionBindingExpression and the query shaper choose values for client code. The work is done when maximum evaluatable subtrees are stored appropriately, conditional entity materialization avoids unnecessary collections, and repeated entities preserve the required tracking or no-tracking behavior.
Written by the indexing model from the issue text.
Description
#21334 talks about not generating variables when we don't need to.
#21335 talks about not boxing when we store them
This issue is about being smart about what we store in variables.
Currently we utilize the ProjectionBindingExpression to store in variables while it is generally ok but there are some cases when a different strategy would actually achieve better perf.
Rather than dealing with ProjectionBindingExpression, we could deal with elements which needs to go into client code instead. In order words, we can take maximum subtree we can evaluate before going into client code and store that in variable instead.
One thing it would solve directly is (which has some overlap with #21334) condition ? EntityA : EntityB scneario where we could skip materializing one entity altogether based on how condition evaluates.
Places to identify what to materialize would generally include
- Top level if projecting a scalar or entity
- Members of NewExpression (recursive)
- Members of MemberInitExpression (basically DTOs) (recursive)
- Arguments being passed to client method or members.
The assumption that maximum subtree would be translated to server remains valid as long as no entities are involved. But with entities the server projection wouldn't be maximum subtree and we need to do that on client side.
A big perf here would be collections when both above entities have collection includes. We could skip materializing and populating whole collection if the entity is not materialized due to the condition. Collection won't be initialized so populate collection should no-op.
A caveat that if the same entity is being reference in multiple spots then we need to make sure we materializes only once. For tracking query it should do identity resolution but no tracking we don't want to create 2 instances.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100