[wp-trac] [WordPress Trac] #63946: Introduce a mechanism for lazy-loading REST routes and handlers
WordPress Trac
noreply at wordpress.org
Mon Sep 8 16:08:04 UTC 2025
#63946: Introduce a mechanism for lazy-loading REST routes and handlers
-------------------------+-----------------------------
Reporter: prettyboymp | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version:
Severity: normal | Keywords:
Focuses: performance |
-------------------------+-----------------------------
Registering REST API routes through controllers introduces additional
overhead on every REST request. Benchmarking shows that the default routes
registered during `create_initial_rest_routes()` take approximately
8.5–10ms in local testing. While this cost is relatively small in
isolation, it is incurred on every request regardless of the endpoint
being accessed. The impact grows even more as plugins register their own
endpoints on top of core routes.
The main performance cost is not from `register_rest_route()` itself, but
from preparing the arguments passed into it. Approximately 20% of this
overhead is attributed to translation handling.
One possible solution would be to introduce a function such as
`register_rest_namespace()`. This would allow a namespace to be declared
during `rest_api_init` without requiring route arguments to be constructed
immediately. At request time, during `rest_pre_dispatch`, a namespaced
hook could be fired for the relevant namespace(s), enabling just-in-time
registration of only the routes required for that request.
For API discovery requests, all namespaces would still need to be fully
registered to ensure complete endpoint visibility. For most other
requests, however, this approach could significantly reduce the cost of
processing for all other requests by avoiding argument construction for
unused routes.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63946>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list