8

I've got to get rid of a lot of unnecessary markup in a view. In general, I accomplish that by overriding the template files in my theme, but this time the view is really huge and performance is going down. So I wondered, if there's a more performant way to reduce markup? When altering the markup of a node, than preprocess functions are faster then overriding template files, is there an analogical mechanism for views?

Edit 1: Sure, the reason for the weak performance is not the overriding of template files on the first place, but if I can optimize a bit there, I'll have to do that. In addition I regularily get into trouble by disabling markup in views UI itself: disableing row-styles for example is ignored when I use an Omega subtheme …

Edit 2: I am aware of the possibilities inside the Views UI; What I am looking for is a manual way with fine control.

  • 3
    What makes you think overriding template files is causing the performance decrease? Not saying it isn't, necessarily, but it feels like that would be unlikely. Unless you're not just stripping out markup but changing the logic too. Maybe you can edit the question and provide a bit more context? Some more specific details about the view and the template file(s)? – Clive Jul 21 '16 at 0:04
  • Added some details above. – Madam Adam Jul 21 '16 at 13:28
  • Slow performance even with caching turned on? (Views cache + Anon page cache + Memcache (perhaps) + Varnish (perhaps)) – Beebee Jul 21 '16 at 13:34
8

You can eliminate unnecessary markup through the Views UI.

When you add a field, hidden under Style Settings, they always have this default unnecessary checkmark

enter image description here

Also, you can remove more markup here

enter image description here

and here

enter image description here

  • Thank you for your answer, but I am aware of the possibilities inside the views ui; what I am looking for is a manual way with fine control. – Madam Adam Jul 21 '16 at 13:32
7

It is sometimes more performant with View to display content instead of fields. This is best leveraged with custom view modes, where you configure the view mode to show the fields you want. You can then make the display of that view mode whatever you want via templates and formatters. This tends to work well when you have Entitycache.

That said, all systems are different. True profiling is really the best way to figure out what is taking time. Personally, I don't think that the views markup is adding any significant time to execution.

  • Interesting approach – I'll profile this. – Madam Adam Jul 21 '16 at 13:30
7

the reason for the weak performance is not the overriding of template files on the first place, but if I can optimize a bit there, I'll have to do that

Sounds like you are being encouraged to prematurely optimize. If the view is suffering performance problems make sure caching is enabled on the view to avoid rendering the HTML from scratch as much as possible. That will provide a far larger boost to performance than almost any reduction in the number of files involved in the rendering process.

Once the theme registry is built having lots of overridden templates shouldn't be a noticeable hit on performance over using the defaults since Drupal is still loading a similar number of files (I have seen an exception to this if you create a file for every possible override in the entire chain, so don't do that).

If you switch to an entity display instead of a field display you may be able to reduce the number of templates loaded and therefore get a minor improvement in render speed. That assumes the entity display also takes steps to avoid field-level templates and/or is likely cached elsewhere already. Likely this would be a lot of expensive human labor for very little improvement in machine performance.

  • 2
    Okay, now the whole mechanism gets clearer to me. On the bottom line, the comments and answers here tend to say it is a wrong and disproportional effort to avoid template overrides in order to speed up performance. Thank you! – Madam Adam Jul 21 '16 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.