fluentassertions / fluentassertions/fluentassertions.json
Configuration of IJsonAssertionOptions slows down comparison a log
- Langage dominant
- C#
- Étoiles
- 73
- Forks
- 30
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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?
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez dans JTokenDifferentiator.CompareValues et suivez la manière dont config.Invoke crée JsonAssertionOptions pour chaque comparaison de valeurs. Reproduisez le ralentissement signalé avec un document JSON volumineux et le callback Using, puis comparez le comportement après avoir modifié le flux des options. C’est terminé lorsque la comparaison de précision est conservée, que le travail répété du builder est évité et qu’une performance acceptable est démontrée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- csharp
- Domaine
- performance, testing
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100