Search code examples
laravelacllaravel-5.7laravel-5.8

Noticeable time increase when checking permissions after updating from laravel 5.7 to laravel 5.8 using silber/bouncer-rc5


I am using bouncer for my ACL needs and ever since upgrading my project from laravel 5.7 to 5.8 I've noticed a significant increase in the time it takes for my requests to process.

I'm dealing with two models (let's call them Parent and Child), as well as the permissions the authenticated user has over them.

// Takes about 110ms. Eager loads various nested relationships and counters with specific constraints
$parents = Parent::myScope(...)->get();

// Bottleneck. Takes 5 minutes (!). Used to take about 40 seconds on laravel 5.7
$parents->each(function ($parent) {
    $parent->permissions = [
        'edit' => auth()->user()->can('edit', $parent),
        'delete' => auth()->user()->can('delete', $parent),
        'restore' => auth()->user()->can('restore', $parent)
    ];
    $parent->children()->each(function ($child) {
        $child->permissions = [
            'edit' => auth()->user()->can('edit', $child),
            'delete' => auth()->user()->can('delete', $child),
            'restore' => auth()->user()->can('restore', $child)
        ];
    }
}

I'm appending the permissions like this because the $parents variable will be sent as json to the front-end. I'm pretty sure this implementation is wrong, and must have a better alternative but the real issue is this inexplicable five-fold increase in loading time.

The times were obtained using Debugbar measures.

Using the monitor command in redis-cli (I'm using Redis to cache the permissions), I've noticed the GET requests come more slowly than before. In fact, even after I stop a page from loading (ESC), the GET requests to Redis don't stop immediately. I'm not sure if this is normal behavior or not.

I tried to check the issues at the bouncer repo but I haven't found anything.


Solution

  • After some testing a solution was found. It turns out, there was no problem with the code at all.

    Something is wrong with the server. We do not know exactly what but trying to run the project on freshly installed machines got rid of those awful processing times. (Now times are at 15s on first request)

    The server's problem got worse coincidentally after migrating from laravel 5.7 to 5.8 which led me to this wild goose chase.

    ADDENDUM

    The culprit was Xdebug. We used it to get code-coverage analysis but the performance was so bad we ended up switching to phpdbg.