By Madam Adam


2016-07-20 22:24:06 8 Comments

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 comments

@acrosman 2016-07-21 13:43:06

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.

@Madam Adam 2016-07-21 13:53:03

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!

@mpdonadio 2016-07-21 01:12:59

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.

@Madam Adam 2016-07-21 13:30:50

Interesting approach – I'll profile this.

@No Sssweat 2016-07-20 22:51:59

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

@Madam Adam 2016-07-21 13:32:29

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.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Is there a better way than twig files overwrite?

  • 2017-09-20 15:23:06
  • Bassem Mohamed
  • 49 View
  • 0 Score
  • 1 Answer
  • Tags:   theming 8 entities

2 Answered Questions

[SOLVED] How to write page.tpl.php where the HTML files is more than one?

  • 2017-09-11 12:47:07
  • Rami Salim
  • 256 View
  • 0 Score
  • 2 Answer
  • Tags:   theming

1 Answered Questions

1 Answered Questions

[SOLVED] View is using original template rather than new custom template

  • 2016-07-08 18:57:49
  • spuppett
  • 39 View
  • 1 Score
  • 1 Answer
  • Tags:   views theming

1 Answered Questions

[SOLVED] Variables in template files

  • 2015-05-27 10:31:39
  • big_smile
  • 67 View
  • 1 Score
  • 1 Answer
  • Tags:   theming

1 Answered Questions

[SOLVED] Which is the most performant way of overriding views field output

0 Answered Questions

2 Answered Questions

[SOLVED] Overriding a specific view mode html.tpl.php template

  • 2013-07-01 01:50:10
  • Citricguy
  • 3766 View
  • 3 Score
  • 2 Answer
  • Tags:   7 theming

2 Answered Questions

1 Answered Questions

[SOLVED] Overriding template without killing the page?

  • 2012-08-23 20:08:25
  • beth
  • 78 View
  • 1 Score
  • 1 Answer
  • Tags:   forms theming

Sponsored Content