Problem/Motivation
After a full cache clear, Drupal has to build up various caches before it can serve a request. Router, menu links, various plugin registries, twig templates, CSS assets (#1014086: Race conditions, stampedes and cold cache performance issues with css/js aggregation) etc.
This both takes a long time, and massively increases the memory usage of a request.
Steps to reproduce
drush cr, load a heavy-ish page, watch that spinny wheel / check mem_get_usage()
Proposed resolution
PHP 8.1 adds Fibers https://php.watch/versions/8.1/fibers / https://wiki.php.net/rfc/fibers
This allows very simple concurrency, and it might allow us to offload some work.
A good use case would be router rebuild. If we create a Fiber for rebuilding the router, we can call that, let it finish, and continue with the main request, but offload all the memory usage of parsing routing YAML etc. to the Fiber.
There might later be the opportunity to move some processing async - for example triggering an async router rebuild from ::setRebuildNeeded() or a more general cache pre-warming step after drupal_flush_caches().