A framework for building native applications using React
Improve performance of performance.mark, performance.measure and console.timeStamp while tracing with RNDT (#53295)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53295 Changelog: [internal] This refactors `PerformanceTracer` to use an intermediate representation for trace events instead of the format expected by Chrome, which improves performance by removing the need to create `folly::dynamic` objects when enqueueing entries (that's moved to the trace processing stage). `performance.mark` and `performance.measure` are only slightly improved because we still need to synchronously create `folly::dynamic` objects when enqueueing entries because we need to get the data from JSI. I made the existing benchmark for the Performance API accurately measure the performance while tracing by forcing enabling the inspector in Fantom and setting the `tracingAtomic_` value to `true`. ## Highlights * `console.timeStamp` (defaults): 1002ns → 580ns (**-42%**) * `console.timeStamp` (all options): 1552ns → 821ns (**-47%**) * `performance.mark` (with custom startTime): 2203ns → 2074ns (-5.8%) * `performance.measure` (with start and end timestamps): 2474ns → 2283ns (-7.7%) ## Full results ### When inspector not used (in "production") (**same before and after**) | (index) | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples | | ------- | --------------------------------------------------------- | ---------------- | ---------------- | ---------------------- | ---------------------- | ------- | | 0 | 'mark (default)' | '1864.5 ± 7.22%' | '1773.0 ± 29.00' | '559978 ± 0.04%' | '564016 ± 9077' | 50000 | | 1 | 'mark (with custom startTime)' | '1780.0 ± 4.31%' | '1723.0 ± 30.00' | '577496 ± 0.04%' | '580383 ± 9932' | 50000 | | 2 | 'measure (default)' | '1906.0 ± 3.87%' | '1852.0 ± 29.00' | '537780 ± 0.04%' | '539957 ± 8590' | 50000 | | 3 | 'measure (with start and end timestamps)' | '1986.3 ± 3.25%' | '1933.0 ± 30.00' | '514216 ± 0.04%' | '517331 ± 7906' | 50000 | | 4 | 'measure (with mark names)' | '2208.7 ± 4.72%' | '2103.0 ± 40.00' | '471058 ± 0.05%' | '475511 ± 8876' | 50000 | | 5 | 'clearMarks' | '665.41 ± 0.17%' | '651.00 ± 20.00' | '1515507 ± 0.06%' | '1536098 ± 48688' | 50000 | | 6 | 'clearMeasures' | '745.87 ± 0.19%' | '721.00 ± 30.00' | '1356547 ± 0.07%' | '1386963 ± 60215' | 50000 | | 7 | 'mark + clearMarks' | '2223.9 ± 1.84%' | '2174.0 ± 39.00' | '456311 ± 0.04%' | '459982 ± 8106' | 50000 | | 8 | 'measure + clearMeasures (with start and end timestamps)' | '2461.0 ± 2.85%' | '2374.0 ± 41.00' | '418624 ± 0.04%' | '421230 ± 7403' | 50000 | | 9 | 'measure + clearMeasures (with mark names)' | '2466.5 ± 3.36%' | '2384.0 ± 50.00' | '416618 ± 0.04%' | '419463 ± 8986' | 50000 | | 10 | 'console.timeStamp (defaults)' | '395.25 ± 0.25%' | '391.00 ± 20.00' | '2554687 ± 0.06%' | '2557545 ± 137873' | 50000 | | 11 | 'console.timeStamp (all options)' | '426.06 ± 0.23%' | '421.00 ± 20.00' | '2369918 ± 0.06%' | '2375297 ± 118469' | 50000 | ### When tracing (before) | (index) | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples | | ------- | --------------------------------------------------------- | ---------------- | ---------------- | ---------------------- | ---------------------- | ------- | | 0 | 'mark (default)' | '2456.2 ± 6.45%' | '2254.0 ± 41.00' | '432571 ± 0.09%' | '443656 ± 8220' | 50000 | | 1 | 'mark (with custom startTime)' | '2354.7 ± 3.39%' | '2203.0 ± 41.00' | '443719 ± 0.09%' | '453926 ± 8394' | 50000 | | 2 | 'measure (default)' | '2661.5 ± 3.30%' | '2414.0 ± 50.00' | '399165 ± 0.11%' | '414250 ± 8762' | 50000 | | 3 | 'measure (with start and end timestamps)' | '2679.1 ± 1.61%' | '2474.0 ± 41.00' | '389798 ± 0.11%' | '404204 ± 6811' | 50000 | | 4 | 'measure (with mark names)' | '2850.0 ± 0.99%' | '2644.0 ± 60.00' | '364185 ± 0.11%' | '378215 ± 8392' | 50000 | | 5 | 'clearMarks' | '687.71 ± 0.43%' | '671.00 ± 20.00' | '1479109 ± 0.05%' | '1490313 ± 43135' | 50000 | | 6 | 'clearMeasures' | '702.69 ± 0.34%' | '691.00 ± 20.00' | '1440497 ± 0.05%' | '1447178 ± 40708' | 50000 | | 7 | 'mark + clearMarks' | '2865.4 ± 1.96%' | '2694.0 ± 50.00' | '363008 ± 0.09%' | '371195 ± 7020' | 50000 | | 8 | 'measure + clearMeasures (with start and end timestamps)' | '3076.2 ± 1.19%' | '2855.0 ± 51.00' | '337615 ± 0.10%' | '350263 ± 6371' | 50000 | | 9 | 'measure + clearMeasures (with mark names)' | '3087.4 ± 0.88%' | '2894.0 ± 60.00' | '334838 ± 0.10%' | '345543 ± 7316' | 50000 | | 10 | 'console.timeStamp (defaults)' | '1203.9 ± 0.60%' | '1002.0 ± 29.00' | '930592 ± 0.18%' | '998004 ± 28072' | 50000 | | 11 | 'console.timeStamp (all options)' | '1885.7 ± 0.44%' | '1552.0 ± 50.00' | '582549 ± 0.20%' | '644330 ± 21449' | 50000 | ### When tracing (after) | (index) | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples | | ------- | --------------------------------------------------------- | ---------------- | ---------------- | ---------------------- | ---------------------- | ------- | | 0 | 'mark (default)' | '2336.9 ± 8.49%' | '2123.0 ± 41.00' | '458093 ± 0.10%' | '471032 ± 9045' | 50000 | | 1 | 'mark (with custom startTime)' | '2229.0 ± 3.55%' | '2074.0 ± 41.00' | '467941 ± 0.10%' | '482160 ± 9724' | 50000 | | 2 | 'measure (default)' | '2367.5 ± 1.85%' | '2233.0 ± 41.00' | '435994 ± 0.09%' | '447828 ± 8168' | 50000 | | 3 | 'measure (with start and end timestamps)' | '2427.0 ± 2.38%' | '2283.0 ± 39.00' | '426361 ± 0.09%' | '438020 ± 7542' | 50000 | | 4 | 'measure (with mark names)' | '2560.9 ± 0.18%' | '2453.0 ± 50.00' | '397989 ± 0.09%' | '407664 ± 8309' | 50000 | | 5 | 'clearMarks' | '677.59 ± 0.20%' | '671.00 ± 20.00' | '1488235 ± 0.05%' | '1490313 ± 45785' | 50000 | | 6 | 'clearMeasures' | '682.91 ± 0.19%' | '671.00 ± 20.00' | '1476825 ± 0.05%' | '1490313 ± 43135' | 50000 | | 7 | 'mark + clearMarks' | '2665.7 ± 1.31%' | '2524.0 ± 50.00' | '386476 ± 0.09%' | '396197 ± 7696' | 50000 | | 8 | 'measure + clearMeasures (with start and end timestamps)' | '2855.4 ± 2.22%' | '2684.0 ± 41.00' | '363742 ± 0.09%' | '372578 ± 5780' | 50000 | | 9 | 'measure + clearMeasures (with mark names)' | '2808.1 ± 0.16%' | '2704.0 ± 50.00' | '361794 ± 0.08%' | '369822 ± 6967' | 50000 | | 10 | 'console.timeStamp (defaults)' | '656.87 ± 0.64%' | '580.00 ± 20.00' | '1669646 ± 0.15%' | '1724138 ± 60244' | 50000 | | 11 | 'console.timeStamp (all options)' | '914.16 ± 0.54%' | '821.00 ± 30.00' | '1173803 ± 0.14%' | '1218027 ± 46196' | 50000 | Reviewed By: rshest Differential Revision: D80263154 fbshipit-source-id: f9e67162a3911a939693fd872bab72a41bc2637f
R
Rubén Norte committed
f9a49e5c562af58c6748ed512263757ec8efb6d5
Parent: 55fa361
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
on 8/18/2025, 11:49:33 AM