fluentassertions / fluentassertions/fluentassertions.json
Configuration of IJsonAssertionOptions slows down comparison a log
- 主要言語
- C#
- スター
- 73
- フォーク
- 30
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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?
コントリビューションガイド
調査の方向性
Start in JTokenDifferentiator.CompareValues and trace how config.Invoke creates JsonAssertionOptions for each value comparison. Reproduce the reported slowdown with a large JSON document and the Using callback, then compare behavior after changing the options flow. Done means preserving the precision comparison while avoiding repeated builder work and demonstrating acceptable performance.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- performance, testing
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100