Skip to content

Conversation

@rogervila
Copy link
Owner

@rogervila rogervila commented Sep 12, 2025

Depends on #60

Refactored Array Comparison Logic

  • The array comparison logic was refactored for better handling of empty arrays, reducing unnecessary iterations.

  • Optimized array key checks to more efficiently identify differences.

Improved Float Comparison

  • Logic for comparing float values was refactored to use epsilon handling, avoiding false positives or negatives when values are mathematically very close but not exactly equal.

  • Additional edge case tests were added, especially around comparisons involving PHP_FLOAT_MAX and infinity.

Overall Performance Gains

All but 2 benchmarks show performance improvements, with most being substantial:

Improvements (>10% faster):

  • benchMixedDataTypes: -27.75% (best improvement)
  • benchWideArrayComparison: -18.60%
  • benchMediumArrayStrictComparison: -18.79%
  • benchMediumArrayLooseComparison: -16.86%
  • benchSmallArrayStrictComparison: -14.30%
  • benchLargeArrayStrictComparison: -14.22%
  • benchLargeArrayLooseComparison: -14.74%
  • benchRealisticUserDataset: -14.05%
  • benchIdenticalArrays: -14.11%
  • benchSmallArrayLooseComparison: -11.38%
  • benchArrayWithNumericKeys: -13.37%
  • benchComplexNestedConfiguration: -12.73%

Minor Regressions (slower):

  • benchCompletelyDifferentArrays: +15.21% slower
  • benchEmptyArrayComparison: +22.41% slower

However, these two regressions are on edge cases (completely different arrays and empty arrays), which are less common in real-world usage.

Key Observations:

Real-world scenarios improved significantly: The realistic user dataset (-14.05%) and complex nested configuration (-12.73%) benchmarks show strong improvements in practical use cases.

Consistent improvements across sizes: Small (-14.30%), medium (-18.79%), and large (-14.22%) arrays all showed substantial improvements.

Wide arrays saw major gains: The -18.60% improvement on wide arrays (100 keys) is particularly impressive.

Variance improvements: Many benchmarks also show reduced standard deviation (rstdev), indicating more consistent performance:

  • benchComplexNestedConfiguration: -51.63% rstdev
  • benchRealisticUserDataset: -31.61% rstdev
  • benchMixedDataTypes: -30.59% rstdev

The optimizations are clearly effective across most scenarios, yielding speed improvements of 10-28% in typical use cases. The minor regressions in edge cases are a worthwhile trade-off for the substantial gains elsewhere.

@rogervila rogervila self-assigned this Sep 12, 2025
@sonarqubecloud
Copy link

@sonarqubecloud
Copy link

@github-actions
Copy link

📊 Benchmark Results

+-----------------------+----------------------------------+-----+------+-----+---------------+------------------+-----------------+
| benchmark             | subject                          | set | revs | its | mem_peak      | mode             | rstdev          |
+-----------------------+----------------------------------+-----+------+-----+---------------+------------------+-----------------+
| ArrayCompareBenchmark | benchSmallArrayStrictComparison  |     | 1000 | 10  | 1.982mb 0.00% | 0.476μs -14.30%  | ±2.73% -1.26%   |
| ArrayCompareBenchmark | benchSmallArrayLooseComparison   |     | 1000 | 10  | 1.982mb 0.00% | 0.540μs -11.38%  | ±2.74% +109.71% |
| ArrayCompareBenchmark | benchMediumArrayStrictComparison |     | 1000 | 10  | 1.982mb 0.00% | 2.404μs -18.79%  | ±1.91% +68.71%  |
| ArrayCompareBenchmark | benchMediumArrayLooseComparison  |     | 1000 | 10  | 1.982mb 0.00% | 2.740μs -16.86%  | ±2.29% +11.01%  |
| ArrayCompareBenchmark | benchLargeArrayStrictComparison  |     | 500  | 10  | 1.982mb 0.00% | 5.671μs -14.22%  | ±1.86% -13.54%  |
| ArrayCompareBenchmark | benchLargeArrayLooseComparison   |     | 500  | 10  | 1.982mb 0.00% | 6.078μs -14.74%  | ±1.50% -24.55%  |
| ArrayCompareBenchmark | benchDeeplyNestedArrayComparison |     | 500  | 10  | 1.982mb 0.00% | 2.447μs -9.49%   | ±1.06% -25.56%  |
| ArrayCompareBenchmark | benchWideArrayComparison         |     | 200  | 10  | 1.982mb 0.00% | 77.356μs -18.60% | ±1.30% +45.19%  |
| ArrayCompareBenchmark | benchIdenticalArrays             |     | 1000 | 10  | 1.982mb 0.00% | 0.390μs -14.11%  | ±1.58% -33.49%  |
| ArrayCompareBenchmark | benchCompletelyDifferentArrays   |     | 1000 | 10  | 1.982mb 0.00% | 0.368μs +15.21%  | ±1.21% -12.28%  |
| ArrayCompareBenchmark | benchMixedDataTypes              |     | 500  | 10  | 1.982mb 0.00% | 1.877μs -27.75%  | ±0.85% -30.59%  |
| ArrayCompareBenchmark | benchRealisticUserDataset        |     | 200  | 10  | 1.982mb 0.00% | 90.397μs -14.05% | ±0.82% -31.61%  |
| ArrayCompareBenchmark | benchComplexNestedConfiguration  |     | 100  | 10  | 1.982mb 0.00% | 13.614μs -12.73% | ±1.39% -51.63%  |
| ArrayCompareBenchmark | benchEmptyArrayComparison        |     | 1000 | 10  | 1.982mb 0.00% | 0.333μs +22.41%  | ±2.40% -5.13%   |
| ArrayCompareBenchmark | benchArrayWithNumericKeys        |     | 500  | 10  | 1.982mb 0.00% | 1.622μs -13.37%  | ±1.78% +13.15%  |
+-----------------------+----------------------------------+-----+------+-----+---------------+------------------+-----------------+


Note: Benchmarks compare PR against master branch.
Performance regression threshold: ±2%

Repository owner deleted a comment from github-actions bot Oct 17, 2025
@rogervila rogervila marked this pull request as ready for review October 17, 2025 10:27
@rogervila rogervila merged commit de7cdfa into master Oct 17, 2025
41 checks passed
@rogervila rogervila deleted the feat-improvements branch October 17, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants