SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 0 C++

Make benchmark for ReactFabricPublicInstance more accurate (#53319)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53319

Changelog: [internal]

We have a microbenchmark for `ReactFabricHostComponent` vs. `ReactNativeElement` but the test code itself is so fast that a big part of its duration is just calling the test function (a noop is 300-500ns, while the duration of these benchmarks is between 800 and 1400ns).

Note that this affects all tests the same way, so the absolute difference in execution time in both tests was still accurate.

This changes how we execute the benchmarks so the test function runs the code under test multiple times and we then report the average of all the runs using the new `overriddenDuration` option.

Before:

| (index) | Task name                  | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
| ------- | -------------------------- | ---------------- | ---------------- | ---------------------- | ---------------------- | ------- |
| 0       | 'noop'                     | '353.83 ± 0.03%' | '350.00 ± 10.00' | '2856842 ± 0.01%'      | '2857143 ± 84034'      | 2826221 |
| 1       | 'ReactNativeElement'       | '1393.8 ± 1.15%' | '1332.0 ± 20.00' | '745853 ± 0.01%'       | '750751 ± 11444'       | 717480  |
| 2       | 'ReactFabricHostComponent' | '884.92 ± 0.59%' | '871.00 ± 21.00' | '1144283 ± 0.01%'      | '1148106 ± 27029'      | 1130046 |

After:

| (index) | Task name                  | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
| ------- | -------------------------- | ---------------- | ---------------- | ---------------------- | ---------------------- | ------- |
| 0       | 'noop'                     | '400.11 ± 0.30%' | '391.00 ± 10.00' | '2532882 ± 0.07%'      | '2557545 ± 67127'      | 50000   |
| 1       | 'ReactNativeElement'       | '868.04 ± 0.04%' | '859.39 ± 4.41'  | '1153974 ± 0.03%'      | '1163616 ± 6002'       | 50000   |
| 2       | 'ReactFabricHostComponent' | '388.79 ± 0.08%' | '384.18 ± 1.91'  | '2579763 ± 0.03%'      | '2602947 ± 13006'      | 50000   |

Reviewed By: rshest

Differential Revision: D80404122

fbshipit-source-id: 7dc6ad34b2e8aa3cb6d62008f97d1c44e325ab27
R
Rubén Norte committed
2726c1ab7c20063d1f941d944b452fbb0cc9771a
Parent: 6b4af38
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 8/18/2025, 3:57:52 PM