Does using a liquid collection slow down the rendering of data in a custom module?
I have a data-intensive custom module, and I trying to speed it up. I would prefer not to use pagination just yet.
Thanks,
Shannon
Does using a liquid collection slow down the rendering of data in a custom module?
I have a data-intensive custom module, and I trying to speed it up. I would prefer not to use pagination just yet.
Thanks,
Shannon
I just did a test, and both ways took about the same amount of time.
Would you be able to share your code?
How are you measuring speed? is it the actual processing time of Liquid or actually the assets on the front-end loading?
The delay is because the custom module is actually called recursively to build a family tree. Iām using an accordion menu from Foundation for the expanding and collapsing, but hereās the page stripped down without Foundation or my CSS:
https://hold-jmb-family-tree-code.treepl.co/testing
Itās taking about 5 seconds to load the simplified version and about 12 seconds with full design, styling, and Foundation.
Hereās the page with full design: https://hold-jmb-family-tree-code.treepl.co/family-tree-1
The Custom Module item represents a family member with custom properties for name, sex, mother [which is of type datasource that points back to this very custom module - the recursive part], and father [which is also of type datasource and points back to this same custom module], and a few more descriptive fields
Hereās the simplified code. It starts with a call to a detail layout specifiying the top node by id, which then calls the list layout to build the hierarchy of ancestors:
{% if this.items | size > 0 %}
<ul >
{% for item in this.items %}
{% if item.name != "Unknown" %}
<li>{{item['firstname']}} {{item.lastname}} {% if item['AlsoKnownAs'] != null %} / {{item['AlsoKnownAs']}}{% endif %} {% if item['MarriedLastNames'] != null %} / {{item['MarriedLastNames']}}{% endif %} {% if item.yearofbirth != null %}[{{item['yearofbirth']}} - {% endif %}{% if item['yearofdeath'] != null %}{{item['yearofdeath']}}{% endif %}{% if item.yearofbirth != null %}]{% endif %}
{% if item['Sex'] | downcase == "female" and item.id != item.mother %}
{% component source: "Family Members", layout: "List-Testing", filterBy: "Mother", filterValue: "{{item['id']}}", limit: "99999", object: "collection", type: "module" %}
{% elsif item.id != item.father %}
{% component source: "Family Members", layout: "List-Testing", filterBy: "Father", filterValue: "{{item['id']}}", limit: "99999", object: "collection", type: "module" %}
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
Hey thatās pretty cool!
When the nested āFamily Membersā components run they are only returning a few items each recursion arenāt they, so I wouldnāt think this should slow down all that much. So it must just be the recursion itself that is slow (not so much the amount of data).
Two main factors come to mind though which might impact the speed here:
object: "list"
rendering method might make a difference???Probably need @vlad.z input here.
The only possible optimisation I could suggest, which may or may not make any difference at all, is whether or not you need the additional condition and item.id != item.mother
? Wouldnāt the current item ID always be different to item.mother
as someone wouldnāt be their own mother? Maybe Iām missing something thoughā¦
ā¦had another thought; where youāre doing {% if this.items | size > 0 %}
, the āsizeā method is a liquid filter which it has to calculate. So maybe try avoiding this and get the total item count directly from an existing value. Should be able to do {% if this.pagination.totalitemscount > 0 %}
Again, no idea if this is more performant but have to try every little thing when it comes to optimisation
I added this because, of course, we had a data input error, which then caused an infinite loop. Someone entered a woman and selected herself as the mother.
Converted the code to use āobjectā instead of ācollectionā,
removed the test on the collection size,
but itās still slow ā¦
I also added some basic CSS to make it look like a real hierarchy
Letās hope itās because itās a trial site. Vlad would need to comment further on thatā¦
We are currently working on a database improvement feature that will significantly increase internal search and filtering speed for any module items (like your case). Itās a high priority at the moment so itās expected to be realeased in one of the upcoming sprints.
That is GREAT news!!! THANKS!
@vlad.z, any progress with Custom Module speed? My family tree which used to take 11 seconds to load is now taking 35 seconds to load.
See my example @ https://hold-jmb-family-tree-code.treepl.co/testing
It is recursively calling the same module. I am now brainstorming pagination ideas.
Thanks,
Shannon
Hi @shannonlynd
We have done some optimization on overall site speed. So your custom solution with Custom Module will most likely speed up after current release update.