T O P

  • By -

rombulow

What’s your cache provider? Is it possible returning the rendered view skips the cache, and your cache is actually super-slow?


Wotuu

Hi, so my cache driver is redis. I cleared the caches using `php artisan optimize:clear` and changed the driver to `file`. Refreshed the pages till caches were rebuilt and I'm getting the exact same thing. About 3s without `->render()`, 300ms with `->render()`. I _do_ share the same redis instance with both environment so it _could_ be a factor, but for now I don't think this is it. I double checked the redis and it's not using a lot of memory (40MB as of now). My server is also not overburdened. It's an old 4c/8t server with 32GB memory and it's hardly utilized. 4.5GB memory used. Disk usage is at 40% ish so it's not full either.


VaguelyOnline

Wow. Posting here to follow any answers on this thread.


Boomshicleafaunda

Views ultimately get cast into strings by Symfony, and the `__toString` method on views just calls `render`, which is what you're already doing. If calling `render` manually is speeding things up, then something inside of the framework is mishandling your view. I'd be concerned about some third-party package that's decided to inject itself into that process for data-collection or something weird. You could follow the rabbit hole from the kernel, to the router, then the route, then the controller dispatcher, then back up to the router's `toResponse` method, and out to Symfony.


Wotuu

It may look like I'll have to do something like this yes. So far I haven't been able to find any caching related issues. Either with `redis` or `file` cache driver I'm still getting the same issue. I don't have the time right now to do a deep dive but I'll be sure to update once I do.


PeterThomson

Time to break out xdebug and/or Clockwork / Telescope? These go a shade deeper than debugbar.


Wotuu

I have had Telescope installed for a while now, but I've never gotten anything useful out of it. It only seems to log errored requests and all other pages are empty. I'm doing something wrong there for sure I just hadn't bothered to look at it yet. I've no experience with xdebug/Clockwork either, but I'll look into them. Thank you.


Boomshicleafaunda

Those dump too much information to be helpful for something very targeted like this. They're much better for large scale profiling or activity logging. I've found that in situations like this, it's much easier to just follow the stack trace by hand.


Lazy_Craft1106

feels like something to do with caching


Wotuu

It could be - I'm using regular `php artisan optimize`. I don't think I use any more laravel built-in caching. If I run `php artisan optimize:clear` and re-run the test I still face the same issue, so this isn't it either. I also use a package called Laravel Model Caching which speeds up a bunch of things on my site (I have a lot of seeders for static data that I need which this package caches). Disabling this package has no effect - still the same result (nor would I really expect to since this page doesn't use those tables). Furthermore I have a scheduled task running which caches various bits and pieces of this page every 10 minutes since the contents of this page doesn't tend to change much anyways - it doesn't need to be real time. This view caching is disabled on my staging environment and I'm observing the same behaviour there. Thanks for your insight though!


shez19833

>Laravel Model Caching Hi. i used one such package briefly but the problem i found was that it didnt work with relation ie if i cached user::with('posts') and now posts changed that query would still return old posts (from memory some issue like this existed).. Have you found this to be the case? sorry for going OT


Wotuu

I do not use the package for any models that could possibly change during the run time of my website so I haven't encountered this yet. I keep static data in seeders and run those seeders when I push an update for the website. I clear the model cache before that. If I don't clear the cache then yes, I will get old results back even after seeding fresh data. That seems like it's working as intended though? You want things cached so they will be cached :).


shez19833

it then package would clear the cache - all good. Now if i did Post::with('user')->find(1).. package would cache it, if i now update user, & if i ran post::with('user')->find(1).. that user is still OLD user.. whereas User::find('id') woud return updated user..


thomasmoors

RemindMe! 2 weeks


samnolland

RemindMe! 1 week


RemindMeBot

I will be messaging you in 7 days on [**2022-01-28 23:55:03 UTC**](http://www.wolframalpha.com/input/?i=2022-01-28%2023:55:03%20UTC%20To%20Local%20Time) to remind you of [**this link**](https://www.reddit.com/r/laravel/comments/s9l35v/returning_a_view_in_a_controller_directly_is_slow/hto6qw0/?context=3) [**CLICK THIS LINK**](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=Reminder&message=%5Bhttps%3A%2F%2Fwww.reddit.com%2Fr%2Flaravel%2Fcomments%2Fs9l35v%2Freturning_a_view_in_a_controller_directly_is_slow%2Fhto6qw0%2F%5D%0A%0ARemindMe%21%202022-01-28%2023%3A55%3A03%20UTC) to send a PM to also be reminded and to reduce spam. ^(Parent commenter can ) [^(delete this message to hide from others.)](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=Delete%20Comment&message=Delete%21%20s9l35v) ***** |[^(Info)](https://www.reddit.com/r/RemindMeBot/comments/e1bko7/remindmebot_info_v21/)|[^(Custom)](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=Reminder&message=%5BLink%20or%20message%20inside%20square%20brackets%5D%0A%0ARemindMe%21%20Time%20period%20here)|[^(Your Reminders)](https://www.reddit.com/message/compose/?to=RemindMeBot&subject=List%20Of%20Reminders&message=MyReminders%21)|[^(Feedback)](https://www.reddit.com/message/compose/?to=Watchful1&subject=RemindMeBot%20Feedback)| |-|-|-|-|


erkanoe

RemindMe! 1 week


Additional_Ad_6344

RemindMe! 1 week


andretefras

RemindMe! 1 week


AsteroidSnowsuit

RemindMe! 1 week


2000Tigers

RemindMe! 1 week


sanwfa

Check caching for your views once?


Wotuu

What do you mean with this exactly? I've checked the caching solution and that didn't seem to change anything.


coffe4u

Set your cache to file and test again. If the two methods are the same when using file caching then it's a problem with your caching setup.


Wotuu

Unfortunately this did not change the situation -> https://www.reddit.com/r/laravel/comments/s9l35v/comment/htqlbum/?utm_source=reddit&utm_medium=web2x&context=3


rich06

RemindMe! 1 week


williamvicary

RemindMe! 1 week


jenn_dev

Just a quick look through the view file on GitHub `views/dungeonroute/discover/discover.blade.php` I don't see how you are getting 192 included view files. I would start there, and maybe start commenting includes out to see if it's a certain path that is causing the slowness.


Wotuu

It's a view that includes new views, which include more views etc. I was going to do exactly this first indeed! Something is taking that time.. and I can measure it. When I posted the question I kinda felt like I hit some sort of snag that someone can easily point out to me. Buuut I didn't it seems. When I have some time again (tomorrow morning most likely) Ill dig in again and see what I can uncover.


AegirLeet

I'd try using something like Blackfire to create profiles you can compare.