From 3016ec5aa67e26d023ada11759d3a596d7831f9a Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 12 Apr 2026 11:26:06 +0200 Subject: [PATCH] reduce routes memory footprint --- CHANGELOG.md | 4 ++++ src/Application/Async/Http.php | 6 ++++-- src/Application/Http.php | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a59df65..72c59b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - `Innmind\Framework\Application::mapRoutes()` +### Changed + +- Reduced routes memory footprint + ## 4.0.2 - 2026-04-12 ### Fixed diff --git a/src/Application/Async/Http.php b/src/Application/Async/Http.php index d865200..df861eb 100644 --- a/src/Application/Async/Http.php +++ b/src/Application/Async/Http.php @@ -77,7 +77,7 @@ public static function of(OperatingSystem $os): self $os, static fn(OperatingSystem $os, Environment $env) => [$os, $env], static fn() => Builder::new(), - Sequence::lazyStartingWith(), + Sequence::of(), static fn(Component $component) => $component, static fn(Component $component) => $component, $notFound, @@ -285,7 +285,9 @@ public function run($input): Attempt { $map = $this->map; $container = $this->container; - $routes = $this->routes; + $routes = Sequence::lazyStartingWith($this->routes)->flatMap( + static fn($routes) => $routes, + ); $notFound = $this->notFound; $mapRoute = $this->mapRoute; $mapRoutes = $this->mapRoutes; diff --git a/src/Application/Http.php b/src/Application/Http.php index 8f7d858..15f31a9 100644 --- a/src/Application/Http.php +++ b/src/Application/Http.php @@ -68,7 +68,7 @@ public static function of(OperatingSystem $os, Environment $env): self $os, $env, static fn() => Builder::new(), - Sequence::lazyStartingWith(), + Sequence::of(), static fn(Component $component) => $component, static fn(Component $component) => $component, $notFound, @@ -267,8 +267,8 @@ public function run($input): Attempt $mapRoutes = $this->mapRoutes; $recover = $this->recover; $pipe = Pipe::new(); - $routes = $this - ->routes + $routes = Sequence::lazyStartingWith($this->routes) + ->flatMap(static fn($routes) => $routes) ->map(static fn($handle) => $handle($pipe, $container)) ->map(static fn($component) => $mapRoute($component, $container)); $router = new Router(