fluentassertions / fluentassertions/fluentassertions.json

Configuration of IJsonAssertionOptions slows down comparison a log

Aperta
#77 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
C#
Stelle
73
Fork
30
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

To check doubles using precision when comparing JSON's, I am using the following options callback in `BeEquivalentTo`:

```cs
options => options.Using(d => d.Subject.Should().BeApproximately(d.Expectation, 0.001))
.WhenTypeIs()
```

But it seems that this builder callback is being called for every value comparison.
JTokenDifferentiator.CompareValues contains:

```cs
using (var scope = new AssertionScope())
{
actual.Value.Should().BeEquivalentTo(expected.Value, options =>
(JsonAssertionOptions)config.Invoke(new JsonAssertionOptions(options)));

hasMismatches = scope.Discard().Length > 0;
}
```

With the addition of the Using, a bigger json (MB's) goes from 200ms to +10s on my PC.

As a workaround, I replicated the behavior of the builder by accessing the `userEquivalencySteps` field on `SelfReferenceEquivalencyAssertionOptions` using reflection and inserting a custom `IEquivalencyStep`, instead of using the fluent API.
This brings it to 1s, which is acceptable for my use case.

Would it make sense to not call this options callback for every JSON value and build it once?
Or would adding API to add a custom `IEquivalencyStep` instead of the builder make sense?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da JTokenDifferentiator.CompareValues e segui il modo in cui config.Invoke crea JsonAssertionOptions per ogni confronto di valori. Riproduci il rallentamento segnalato con un documento JSON di grandi dimensioni e il callback Using, quindi confronta il comportamento dopo aver modificato il flusso delle options. Il lavoro è completato quando viene preservato il confronto di precisione, si evita il lavoro ripetuto del builder e si dimostrano prestazioni accettabili.

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

Valutazione

Stack tecnologico
csharp
Ambito
performance, testing
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.