php - Laravel Octane concurrently very slow to resource model

one text

I'm trying to improve the performance of my model resources. This is a simple test that without Octane corrotine takes 2 seconds. I tried to divide them and play inside a coroutine but the time that used to be 2 seconds, became 24 seconds, when in fact it should decrease the time and not increase it.

Steps To Reproduce: This was the code I tested:

public function toArray($request): array
{
    [$price_table, $products] = Octane::concurrently([
        fn() => [
            'id'                 => $this->id,
            'name'               => $this->name,
            'client_id'          => $this->client_id,
            'price_table_id'     => $this->price_table_id,
            'template'           => $this->template,
            'active_to_contract' => $this->active_to_contract,
            'active'             => $this->active,
            'created_at'         => $this->created_at,
            'updated_at'         => $this->updated_at,
        ],
        fn() => ['products' => ProductResource::collection($this->products)],
    ]);

    return [
        ...$price_table,
        ...$products,
    ];
}

Hi,

I also noticed that the time octane saves when executing functions, it loses in returning them...ex:

This function takes 1 second;

[$user, $prod, $client] = Octane::concurrently([
     fn() => \App\Api\User\Models\UserModel::all(),
     fn() => \App\Api\Product\Models\ProductModel::all(),
     fn() => \App\Api\Client\Models\ClientModel::all(),
]);

Its return takes 4 seconds:

return [$user, $prod, $client];

The impression I have is that it's only worth using when you don't need to return them via response to the browser

Source