Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Configuration of IJsonAssertionOptions slows down comparison a log

オープン
#77 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp

調査の方向性

JTokenDifferentiator.CompareValues から始め、config.Invoke が値の比較ごとに JsonAssertionOptions を作成する流れを追跡します。大きな JSON ドキュメントと Using callback を使って報告された速度低下を再現し、その後 options のフローを変更した場合の動作を比較します。精度比較を維持しながら、builder の作業の繰り返しを避け、許容可能なパフォーマンスを示せれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug

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

options => options.Using<double>(d => d.Subject.Should().BeApproximately(d.Expectation, 0.001))
  .WhenTypeIs<double>()

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

using (var scope = new AssertionScope())
{
    actual.Value.Should().BeEquivalentTo(expected.Value, options =>
        (JsonAssertionOptions<object>)config.Invoke(new JsonAssertionOptions<object>(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?

主要言語
C#
スター
73
フォーク
30
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。