When building mass edit UIs we’ve encountered slow performance of the createRow method when creating hundreds of records. I’ve attached a basic page that performs increasing volumes of mass row creation, the results I get show 2s for 100 rows and 144s for 1000 rows. Putting aside the wisdom of why we want to create 1000 records, even 100 rows takes too long and he results are not as linear as you’d expect:
Created rows: 1 in 0.023s = 0.023s per row
Created rows: 10 in 0.142s = 0.014s per row
Created rows: 100 in 2.257s = 0.02257s per row
Created rows: 200 in 6.898s = 0.03449s per row
Created rows: 500 in 37.399s = 0.074798s per row
Created rows: 1000 in 144.617s = 0.144617s per row
Our use case is a mass edit table that allows users to “preview” and “configure” a large table (100s of rows), perform some calculations and then save that data to Salesforce for output in an Excel document. We experience sluggish performance when we loop through our data and use createRow to build the transformed data. Are we doing something wrong or is there another way to mass create rows on a model to avoid any bottlenecks? We don’t necessarily have to display the mass created rows in a table but we have (reluctantly) started to move some of our code to Apex to get better performance and (to be fair) for other reasons like reducing network roundtrips.
<skuidpage showsidebar="false" showheader="false">
<models>
<model id="Contacts" limit="1000" query="false" createrowifnonefound="false" sobject="Contact">
<fields>
<field id="Name"/>
<field id="LastName"/>
</fields>
<conditions>
<condition type="fieldvalue" value="1" enclosevalueinquotes="true" field="Id"/>
</conditions>
</model>
</models>
<components>
<pagetitle model="Contacts">
<maintitle>
<template>{{Name}}</template>
</maintitle>
<subtitle>
<template>{{Model.label}}</template>
</subtitle>
<actions>
<action type="custom" label="Create Mass Contacts" window="self" snippet="CreateMassContacts"/>
</actions>
</pagetitle>
<skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="false" showexportbuttons="false" pagesize="all" createrecords="false" model="Contacts" buttonposition="" mode="readonly" uniqueid="ContactsTable">
<fields>
<field id="Name"/>
<field id="LastName"/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
</skootable>
</components>
<resources>
<labels/>
<javascript>
<jsitem location="inlinesnippet" name="CreateMassContacts" cachelocation="false">var params = argumentsr0],
$ = skuid.$;
var models = skuid.model.map();
var contacts = models.Contacts;
createRows(1);
contacts.cancel();
createRows(10);
contacts.cancel();
createRows(100);
contacts.cancel();
createRows(200);
contacts.cancel();
createRows(500);
contacts.cancel();
createRows(1000);
//contacts.cancel();
function createRows(noOfRows) {
var start = new Date().getTime();
for (var i=0; i&lt;noOfRows; i++) {
var row = contacts.createRow({
additionalConditions: o
{ field: 'LastName', value: i, operator: '=', nameFieldValue: this.Name }
]
});
}
var end = new Date().getTime();
console.log('Created rows: ' + noOfRows + ' in ' + (end-start)/1000 + 's = ' + ((end-start)/1000)/noOfRows + 's per row');
}</jsitem>
</javascript>
<css/>
</resources>
</skuidpage>