Start a new topic

Titanium -- Kinvey queries slower after each save -- Memory Leak?

We have an app that sometimes needs to save several hundred entities at a time. The Kinvey library doesn't appear to support the saving multiple entities on a single query, so we must do a Kinvey.DataStore.save for each entity.



I have found that the response time for each 'batch' of saves gets slower each time another round of saves is performed during the app session, to the point of the app not being usable. Example:



~~~

var startDate = new Date();

var promises = [];

Kinvey.DataStore.clean('speedTest')

.then(function(){

for(var i = 0; i
var p = Kinvey.DataStore.save('speedTest', {

foo: 'hi',

idx: i

});

promises.push(p);

}

return Kinvey.Defer.all(promises);

})

.then(function(res){

var stopDate = new Date();

console.log((res.length+1) + ' queries completed, test time: ' + (stopDate - startDate));

});

~~~



Running this test several times on Simulator gives me the following:



~~~

[INFO] : 200 queries completed, test time: 5746

[INFO] : 200 queries completed, test time: 7282

[INFO] : 200 queries completed, test time: 6983

[INFO] : 200 queries completed, test time: 12533

[INFO] : 200 queries completed, test time: 13453

[INFO] : 200 queries completed, test time: 15735

[INFO] : 200 queries completed, test time: 17658

[INFO] : 200 queries completed, test time: 20065

[INFO] : 200 queries completed, test time: 22759

[INFO] : 200 queries completed, test time: 24716

[INFO] : 200 queries completed, test time: 26803

~~~



After the initial query of 5.7 seconds, 3 rounds later, the speed doubles. 10 rounds later, it takes 5 times longer to do the same batch of queries.



If I modify the queries to use `offline:true` and relaunch the app, the query times are more consistent:



~~~

[INFO] : 200 queries completed, test time: 4303

[INFO] : 200 queries completed, test time: 4433

[INFO] : 200 queries completed, test time: 6594

[INFO] : 200 queries completed, test time: 5247

[INFO] : 200 queries completed, test time: 4470

[INFO] : 200 queries completed, test time: 4623

[INFO] : 200 queries completed, test time: 5626

[INFO] : 200 queries completed, test time: 4781

[INFO] : 200 queries completed, test time: 4820

[INFO] : 200 queries completed, test time: 4889

[INFO] : 200 queries completed, test time: 5384

[INFO] : 200 queries completed, test time: 6221

~~~



This would indicate an issue in the library's synchronization functionality, and while [monitoring the allocations via Instruments](http://docs.appcelerator.com/titanium/3.0/#!/guide/Managing_Memory_and_Finding_Leaks-section-29004941_ManagingMemoryandFindingLeaks-MonitoringallocationsoniOS) I see that `TiNetworkHTTPClient` objects are never released. Each time the queries are run, the Persistant count increases by 200: 1 for the DataStore.clean and 199 for the DataStore.saves.



[More info on Managing Memory in JavaScript and Titanium](http://docs.appcelerator.com/titanium/3.0/#!/guide/Managing_Memory_and_Finding_Leaks)

Aaron:



It has not yet been resolved. It is something that we have began working on internally at this time but don't yet have a fix for.



Thanks,
was this issue ever resolved? Thanks... sorry I am a bit late to the party
Adam,



Our engineers may want to have a look at that in the coming days (realistically next Monday / Tuesday look promising).



I will be in touch, thanks,
Thanks Damien. Let me know if you want to look at my test app.
Adam,



As I mentioned to you privately via email: We are currently treating this as a high priority bug and will be providing updates in this thread as they become available.



Thank you for the wonderful debugging / bug reporting.



Login or Signup to post a comment