0

I have pretty big View which returns hundreds of rows and I am struggling with View render time. Stats are as follow:

Query build time: 44.69 ms
Query execution time: 111.52 ms
View render time: 6978.68 ms

Problem is this view differs from user to user so caching is not effective. It gets build for the first time user visits the website and this takes 7 seconds, then it runs smoothly. But if anything changes in this table, whole cache gets invalidated for all the users and they again wait 7 seconds to render the website.

I tried direct queries in hook_preprocess_views_view_field where I tried either fetching values with NID with entityTypeManager() in hopes of bypassing whatever is happening in the background or direct queries to database and tables but this was no faster.

My guess is there is so much stuff going on for EACH of the row / field in terms of build-in hooks, event subscribers, theme files etc. which I have no control over that together they make up the majority of views render time.

How can I speed up a View like that?

6
  • Have you used PHP profiling tools? xhprof or Blackfire will point to code that executes slowly or too often, or both.
    – cilefen
    Mar 21 at 15:32
  • Does your query use fields or a rendered entity for the results? Mar 21 at 17:39
  • I tried web profiler but there were no "slow queries" and I couldn't quite make up anything useful from the rest. There is no xhprof available. I am using fields, not rendered entities but the view has lots of filtering and relationships to taxonomies but overall I am printing just strings with no further functionality, not even links. But query build and execution is fast so my guess is theming and hooks is what takes most of the time.
    – Lub
    Mar 21 at 18:13
  • 1
    When you render view fields the single rows get cached. Then the entire View is probably cached as a block or a page. The question is why every change to the table invalidates the entire cache and not only parts of it. You could also use a pager. What happens if you remove temporarily some fields? Which fields are the most time consuming?
    – 4uk4
    Mar 21 at 20:01
  • 1
    Returns hundreds of rows… use pagination or use Views infinite scroll and load small chunks at a time. (Max 50 I would advice)
    – No Sssweat
    Mar 23 at 15:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.