[wp-trac] [WordPress Trac] #52992: REST API: Avoid unnecessarily preparing item links

WordPress Trac noreply at wordpress.org
Sun Nov 7 18:16:31 UTC 2021


#52992: REST API: Avoid unnecessarily preparing item links
-------------------------------------------------+-------------------------
 Reporter:  dlh                                  |       Owner:
                                                 |  rachelbaker
     Type:  enhancement                          |      Status:  accepted
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  REST API                             |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  testing needs-testing-info                     |
-------------------------------------------------+-------------------------
Changes (by dlh):

 * keywords:
     has-patch has-unit-tests needs-testing needs-refresh needs-testing-
     info
     => has-patch has-unit-tests needs-testing needs-testing-info


Comment:

 I've updated the Pull Request to address the merge conflicts.

 I've also added a PHPBench benchmarking class that evaluates the
 performance of dispatching the same REST API request to the terms endpoint
 that was included in the ticket description.

 (The class was modeled on a benchmarking class in a Pull Request for
 #53218: https://github.com/WordPress/wordpress-develop/pull/1259.)

 The benchmarking class is not meant to be committed, of course, but it
 should allow for others to run the same benchmarks for the changes in this
 ticket or explore their own. I also hadn't used PHPBench before, so it
 would be good to have more pairs of eyes on the benchmark class itself for
 any mistakes.

 To add PHPBench to my local development environment for testing, I ran
 `composer require phpbench/phpbench --dev` from the `wordpress-develop`
 root.

 I then used [https://phpbench.readthedocs.io/en/latest/guides/regression-
 testing.html#compare-against-the-baseline steps from the PHPBench
 documentation] to create a baseline measurement on the `master` branch:

 `vendor/bin/phpbench run tests/Benchmark/ --tag=original`

 and then a comparison with the branch in the Pull Request:

 `vendor/bin/phpbench run tests/Benchmark/ --report=aggregate
 --ref=original`

 In my local environment, running PHP 7.4, PHPBench typically reported
 around a 60% decrease in wall time and a minor decrease in memory usage to
 dispatch the request with the patch applied. Here's an example report from
 the comparison run:

 {{{
 +-----------------------+-------------------+-----+------+-----+-----------------+-----------------+-----------------+
 | benchmark             | subject           | set | revs | its | mem_peak
 | mode            | rstdev          |
 +-----------------------+-------------------+-----+------+-----+-----------------+-----------------+-----------------+
 | RestPrepareLinksBench | bench_default     |     | 1000 | 5   | 23.624mb
 -1.72% | 2.555ms -64.15% | ±1.23% -61.63%  |
 | RestPrepareLinksBench | bench_with_filter |     | 1000 | 5   | 23.625mb
 -1.71% | 2.479ms -67.04% | ±3.42% +269.48% |
 +-----------------------+-------------------+-----+------+-----+-----------------+-----------------+-----------------+
 }}}

 In terms of manual or smoke testing, the main things to check would be:

 1. The `_links` property is included in REST API responses when `_fields`
 isn't specified or when it includes `_links`.
 2. Requests with `_embed` included the expected embedded resources.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52992#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list