Skip to content

Performance: Piped route middleware - #991

Draft
jvangestel wants to merge 7 commits into
2.xfrom
feature/runtime-pipe-route-middleware
Draft

Performance: Piped route middleware#991
jvangestel wants to merge 7 commits into
2.xfrom
feature/runtime-pipe-route-middleware

Conversation

@jvangestel

Copy link
Copy Markdown
Contributor

Instead of adding custom middleware to every group, we pipe those middleware on runtime, making the route preperation faster.

Currently preparing the routes middleware takes a lot of calls, because every middleware gets prepared for all the routes (800+ routes * 10'ish middleware.. ). By creating a custom piping mechanism, we can check which routeGroup it belongs to on runtime, and then pipe it through the specific middleware, before continueing!
This way we do not have to prepare middleware for routes we currently aren't on.

The route group name as defined in the Routegroup in Route.php will get injected in the route options, so we know which route belongs to which route group on runtime.

This WILL require some project specific changes:

config/pipeline.php (after the config piuplines on r79:

use \Gems\Route\MiddlewareGroup;

$app->pipe(new MiddlewareGroup($container, $config['routeGroups'] ?? []));

Also the routeGroup trait has changed:

  1. It requires a routeGroup name as first param, corresponding to the desired route group.
  2. The middleware section can now be removed.

This would need to be refactored in all Route/apiRoute config files...

@mddejong

mddejong commented Apr 2, 2026

Copy link
Copy Markdown
Member

All projects except for Pulse now use Gems\InitFunctions in their index.php.

You can fix this their as part of the central code.

@jvangestel
jvangestel force-pushed the feature/runtime-pipe-route-middleware branch from 8f4e4d7 to 78b56f4 Compare June 23, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants