Skip to content

Micro-optimize performance methods #52555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

rubennorte
Copy link
Contributor

Summary:
Changelog: [internal]

Applied several micro-optimizations to methods in the performance object:

  • Cached property access
  • Avoided unnecessary function calls
  • Avoided unnecessary object allocations
  • Use strict comparisons with undefined instead of loose comparisons with null whenever possible.

This yields wins from 5 to 15% depending on the method and args.

Before

(index) Task name Latency average (ns) Latency median (ns) Throughput average (ops/s) Throughput median (ops/s) Samples
0 'mark (default)' '1728.19 ± 0.81%' '1682.00' '592249 ± 0.01%' '594530' 578640
1 'mark (with custom startTime)' '2008.33 ± 1.32%' '1933.00' '514326 ± 0.01%' '517331' 497927
2 'measure (default)' '2568.90 ± 1.48%' '2484.00' '400362 ± 0.02%' '402576' 389272
3 'measure (with start and end timestamps)' '2806.21 ± 0.69%' '2744.00' '362439 ± 0.02%' '364431' 356353
4 'measure (with mark names)' '2860.82 ± 0.23%' '2824.00' '352145 ± 0.02%' '354108' 349551
5 'clearMarks' '763.05 ± 0.03%' '751.00' '1320377 ± 0.01%' '1331558' 1310524
6 'clearMeasures' '788.10 ± 0.05%' '781.00' '1281839 ± 0.01%' '1280410' 1268875
7 'mark + clearMarks' '2129.03 ± 1.04%' '2053.00' '484778 ± 0.01%' '487092' 469698
8 'measure + clearMeasures (with start and end timestamps)' '3176.38 ± 0.67%' '3105.00' '320111 ± 0.02%' '322061' 314825
9 'measure + clearMeasures (with mark names)' '3229.33 ± 0.60%' '3145.00' '316463 ± 0.02%' '317965' 309662

After

(index) Task name Latency average (ns) Latency median (ns) Throughput average (ops/s) Throughput median (ops/s) Samples
0 'mark (default)' '1598.54 ± 0.93%' '1553.00' '639076 ± 0.01%' '643915' 625572
1 'mark (with custom startTime)' '1772.07 ± 1.24%' '1713.00' '579523 ± 0.01%' '583771' 564314
2 'measure (default)' '2349.32 ± 0.81%' '2284.00' '434149 ± 0.01%' '437828' 425656
3 'measure (with start and end timestamps)' '2609.11 ± 1.06%' '2534.00' '391950 ± 0.02%' '394633' 383273
4 'measure (with mark names)' '2656.46 ± 0.42%' '2614.00' '380128 ± 0.01%' '382555' 376442
5 'clearMarks' '666.38 ± 0.03%' '661.00' '1511649 ± 0.01%' '1512859' 1500641
6 'clearMeasures' '718.62 ± 0.03%' '711.00' '1401526 ± 0.01%' '1406470' 1391563
7 'mark + clearMarks' '2027.47 ± 1.29%' '1953.00' '509105 ± 0.01%' '512033' 493227
8 'measure + clearMeasures (with start and end timestamps)' '3030.83 ± 0.98%' '2915.00' '340624 ± 0.02%' '343053' 329943
9 'measure + clearMeasures (with mark names)' '2915.76 ± 0.59%' '2844.00' '349120 ± 0.02%' '351617' 342964

Differential Revision: D78013565

…correctly

Summary:
Changelog: [internal]

Making `performance.mark` and `performance.measure` slightly more spec-compliant.

Differential Revision: D78013571
Summary:
Changelog: [internal]

Small refactors for `$ReadOnly`, move `getCurrentTimeStamp` to utils so it can be reused, etc.

Differential Revision: D78013570
…mance.measure

Summary:
Changelog: [internal]

`PerformanceEntry.detail` should be `null` if not defined, not undefined as it is currently. This fixes that.

Differential Revision: D78013568
Summary:
Changelog: [internal]

This adds a new benchmark for `performance.measure` to measure the performance of calling it without arguments.

Differential Revision: D78013563
Summary:
Changelog: [internal]

Applied several micro-optimizations to methods in the `performance` object:
- Cached property access
- Avoided unnecessary function calls
- Avoided unnecessary object allocations
- Use strict comparisons with `undefined` instead of loose comparisons with `null` whenever possible.

This yields wins from 5 to 15% depending on the method and args.

## Before

| (index) | Task name                                                 | Latency average (ns) | Latency median (ns) | Throughput average (ops/s) | Throughput median (ops/s) | Samples |
| ------- | --------------------------------------------------------- | -------------------- | ------------------- | -------------------------- | ------------------------- | ------- |
| 0       | 'mark (default)'                                          | '1728.19 ± 0.81%'    | '1682.00'           | '592249 ± 0.01%'           | '594530'                  | 578640  |
| 1       | 'mark (with custom startTime)'                            | '2008.33 ± 1.32%'    | '1933.00'           | '514326 ± 0.01%'           | '517331'                  | 497927  |
| 2       | 'measure (default)'                                       | '2568.90 ± 1.48%'    | '2484.00'           | '400362 ± 0.02%'           | '402576'                  | 389272  |
| 3       | 'measure (with start and end timestamps)'                 | '2806.21 ± 0.69%'    | '2744.00'           | '362439 ± 0.02%'           | '364431'                  | 356353  |
| 4       | 'measure (with mark names)'                               | '2860.82 ± 0.23%'    | '2824.00'           | '352145 ± 0.02%'           | '354108'                  | 349551  |
| 5       | 'clearMarks'                                              | '763.05 ± 0.03%'     | '751.00'            | '1320377 ± 0.01%'          | '1331558'                 | 1310524 |
| 6       | 'clearMeasures'                                           | '788.10 ± 0.05%'     | '781.00'            | '1281839 ± 0.01%'          | '1280410'                 | 1268875 |
| 7       | 'mark + clearMarks'                                       | '2129.03 ± 1.04%'    | '2053.00'           | '484778 ± 0.01%'           | '487092'                  | 469698  |
| 8       | 'measure + clearMeasures (with start and end timestamps)' | '3176.38 ± 0.67%'    | '3105.00'           | '320111 ± 0.02%'           | '322061'                  | 314825  |
| 9       | 'measure + clearMeasures (with mark names)'               | '3229.33 ± 0.60%'    | '3145.00'           | '316463 ± 0.02%'           | '317965'                  | 309662  |

## After

| (index) | Task name                                                 | Latency average (ns) | Latency median (ns) | Throughput average (ops/s) | Throughput median (ops/s) | Samples |
| ------- | --------------------------------------------------------- | -------------------- | ------------------- | -------------------------- | ------------------------- | ------- |
| 0       | 'mark (default)'                                          | '1598.54 ± 0.93%'    | '1553.00'           | '639076 ± 0.01%'           | '643915'                  | 625572  |
| 1       | 'mark (with custom startTime)'                            | '1772.07 ± 1.24%'    | '1713.00'           | '579523 ± 0.01%'           | '583771'                  | 564314  |
| 2       | 'measure (default)'                                       | '2349.32 ± 0.81%'    | '2284.00'           | '434149 ± 0.01%'           | '437828'                  | 425656  |
| 3       | 'measure (with start and end timestamps)'                 | '2609.11 ± 1.06%'    | '2534.00'           | '391950 ± 0.02%'           | '394633'                  | 383273  |
| 4       | 'measure (with mark names)'                               | '2656.46 ± 0.42%'    | '2614.00'           | '380128 ± 0.01%'           | '382555'                  | 376442  |
| 5       | 'clearMarks'                                              | '666.38 ± 0.03%'     | '661.00'            | '1511649 ± 0.01%'          | '1512859'                 | 1500641 |
| 6       | 'clearMeasures'                                           | '718.62 ± 0.03%'     | '711.00'            | '1401526 ± 0.01%'          | '1406470'                 | 1391563 |
| 7       | 'mark + clearMarks'                                       | '2027.47 ± 1.29%'    | '1953.00'           | '509105 ± 0.01%'           | '512033'                  | 493227  |
| 8       | 'measure + clearMeasures (with start and end timestamps)' | '3030.83 ± 0.98%'    | '2915.00'           | '340624 ± 0.02%'           | '343053'                  | 329943  |
| 9       | 'measure + clearMeasures (with mark names)'               | '2915.76 ± 0.59%'    | '2844.00'           | '349120 ± 0.02%'           | '351617'                  | 342964  |

Differential Revision: D78013565
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Jul 11, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D78013565

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in f5abce0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants