Cosmos: Handle late discriminators in materialization

Aperta
#38,576 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
csharp
Ambito
database

Direzione di ricerca

Inizia esaminando la materializzazione Cosmos in streaming introdotta da #38550, concentrandoti sulla scansione del discriminator di Utf8JsonReader e sull'ordinamento dei discriminator del serializer. Confronta il comportamento dei discriminator tardivi con gli approcci menzionati basati sulle eccezioni STJ DOM e opt-out; il completamento richiede che sia stata decisa una strategia e che siano state eseguite le relative verifiche delle prestazioni e della correttezza.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area-cosmos area-perf area-query customer-reported
What problem are you trying to solve?

Since #38550 cosmos materialization is done in a streaming fashion, using Utf8JsonReader.
This is faster and allocation light. Especially when comparing the to previous materializer that used Newtonsoft's DOM as an intermediate step.
However, when a structural type has an inheritance hierarchy, the materializer needs to know the discriminator value before it can start reading other values. Similar to STJ, the materializer will do a scan over the document to find the discriminator property and it's value. A document could be as large as 2MB and the discriminator can appear anywhere in the document. Limited benchmarking has shown that scanning the document can be slow when the discriminator appears late, to the point where STJ's DOM would be faster with very little increase in GC pressure.
The serializer has been changed to put discriminators early in the document, but using different write method or migrating from an older version of EF, we don't know the location of the discriminator

Describe the solution you'd like

To discuss.
STJ actually throws an opt-out exception when the discriminator is not the first property in a json document that has an inheritance hierarchy. We could consider the same, or even switch to DOM when we can't find the discriminator in the first (few) properties. This would mean maintaining 2 methods of materialization tho, which probably isn't worth it. Completely switching to STJ DOM could be an option, but we would be slightly slowing down the happy path materialization.

Lingua principale
C#
Stelle
14.8k
Fork
3.4k
Merge medio
3g 18h
PR unite (30g)
159

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/efcore

Tutte le issue di dotnet/efcore

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.