This is a migrated thread and some comments may be shown as answers.

Extreme performance issue with Hierachical DS/TreeView when loadOnDemand=false

4 Answers 212 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 29 Nov 2012, 10:21 AM

Every node causes a call to _initChildren even if it doesn't have children.

If i have one root node with 1000 children (leafs w/o children) the call to _initChildren is made 1001 times. If you use load on demand the call is only done for the nodes you expand, and nodes without children can't be expanded. It is obvious that the information on wheter the node has children or not is available before the _initChildren is called. For larges datasources (~1000 nodes) this often causes the browser to halt (alerting ~A script is causing the page to run slowly..).

By changing kendo.data.js (start line 2832 in 2012.2.913) from:

load: function() {
    var that = this,
        options = {};
 
    that._initChildren();
 
    if (!that._loaded || that.hasChildren) {
        options[that.idField || "id"] = that.id;
 
        if (!that._loaded) {
            that.children._data = undefined;
        }
 
        that.children.one(CHANGE, function() {
                    that._loaded = true;
                })
                ._query(options);
    }
},

To:

load: function() {
    var that = this,
        options = {};
 
    if (that.hasChildren)
    {
        that._initChildren();
 
        options[that.idField || "id"] = that.id;
 
        if (!that._loaded) {
            that.children._data = undefined;
        }
 
        that.children.one(CHANGE, function() {
                    that._loaded = true;
                })
                ._query(options);
    }
},

The loading time is cut by ~80% (one typical example would be from 30s to 7s) in my average trees (a lot more in the example given above).

Though I don't now it the above code change can have any unforseen consequences, or if there is a better way to accomplish a similar effect.

Would love to hear you thoughts on this.

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 30 Nov 2012, 11:26 AM
Hello David,

Thank you for reporting this. The said change will break the append/insertBefore/insertAfter operations in the treeview, because the items will not have valid child datasources after load() -- leaf nodes do not have their hasChildren flag set, and calling load() will not initialize their child datasource.

We are looking for a resolution of this problem at this time, and I'll update this thread with our findings later today.

Regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alex Gyoshev
Telerik team
answered on 30 Nov 2012, 01:41 PM
Hello again,

The last issue that I described can be addressed by adding the following lines to the _dataSourceMove method from kendo.treeview.js:

// kendo.treeview.js : _dataSourceMove()
// OLD
if (parentNode != this.root) {
    destDataSource = referenceDataItem.children;
}

// NEW
if (parentNode != this.root) {
    destDataSource = referenceDataItem.children;

    if (!destDataSource || $.isPlainObject(destDataSource)) {
        referenceDataItem._initChildren();
        destDataSource = referenceDataItem.children;
    }
}

// kendo.data.js : load()
// OLD
that._initChildren();

if (!that._loaded || that.hasChildren) {

// NEW
if (that.hasChildren) {
    that._initChildren();

However, this will break any user code that has accesses the children field without checking whether it exists. Since we are reluctant to add such a breaking change in the internal builds, we will introduce this change in a future official release.

All the best,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sean Smith
Top achievements
Rank 1
answered on 19 Jan 2013, 12:06 AM
Is this issue the same as this item from a recent release notes document?

Loading nodes with hasChildren=false queries the child data source

It seems that it was an issue that was fixed, but that does not appear to be the case. If not, can you please provide the min version of the code to replace?
0
Alex Gyoshev
Telerik team
answered on 21 Jan 2013, 07:37 AM
Hello Sean,

While this fix improves the overall HDS performance, it is not the same issue. Alas, since the service pack is a non-breaking release, so the breaking change will be introduced in the 2013.Q1 release.

Please note that we do not provide updated files in public threads. If you need an updated version of any file, please request it through a support ticket.

All the best,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Hierarchical Data Source
Asked by
David
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Sean Smith
Top achievements
Rank 1
Share this question
or