You have all the answers in this post.
Dec 1, 2022
7
Level 1
Array vs non-array for performance of multiple middlewares
Given that mw1, mw2, and mw3 middleware do the same CPU work in the code, which code of the following 4 code examples will offer the best performance and why?
Code A:
Route::middleware(['mw1', 'mw2', 'mw3'])->group(function () {
Route::get('/test', [TestController::class, 'index'])->name('test');
});
Code B:
Route::middleware(['mw1','mw2'])->group(function () {
Route::middleware('mw3')->group(function () {
Route::get('/test', [TestController::class, 'index'])->name('test');
});
});
Code C:
Route::middleware('mw1')->group(function () {
Route::middleware(['mw2', 'mw3'])->group(function () {
Route::get('/test', [TestController::class, 'index'])->name('test');
});
});
Code D:
Route::middleware('mw1')->group(function () {
Route::middleware('mw2')->group(function () {
Route::middleware('mw3')->group(function () {
Route::get('/test', [TestController::class, 'index'])->name('test');
});
});
});
Please or to participate in this conversation.