This is not a question, but one of my findings after spending some significant time on Lightning framework.
Problem : I was querying ~3k accounts and related child objects and was building a wrapper class to return the response back to the lightning app. The code looked something like this
Public Class AccountQueryController{
@AuraEnabled
Public Static List<AccountWrapper> queryAllAccounts(){
List<AccountWrapper> accountWrapperList = New List<AccountWrapper>();
List<Account> myAccounts = [Select id, Name, BillingState.
(Select id
From Contacts)
From Account];
if(!myAccounts.isEmpty()){
for(Account currentAccount : myAccounts){
accountWrapperList.add(new AccountWrapper (..) );
}
}
return accountWrapperList;
}
Public Class AccountWrapper{
@AuraEnabled
Account currentAccount;
@AuraEnabled
Integer noOfContacts;
@AuraEnabled
Boolean isPartnerAccount;
@AuraEnabled
//Few more variables
Public AccountWrapper(Account currentAccount, Integer noOfContacts, Boolean isPartnerAccount, ..){
this.currentAccount = currentAccount;
....
}
}
}
It was taking close to 8 Seconds to load the component and which from user experience is quite a lot of time.
Solution After exploring chrome JS console for event timelines and SF developer console to understand the server process time for query handling and returning the response, I realised AURA framework was taking a lot of time to create the auraBindings for wrapper class variables. There were plenty of aura statements in the logs.
Just to experiment with the component performance, I decided to modify the response type and return a JSON object string, instead of an object list itself.
To my surprise, it improved the component performance quite significantly and brought it down to ~3 seconds (Which it not too bad).
Public Class AccountQueryController{
@AuraEnabled
Public Static List<AccountWrapper> queryAllAccounts(){
List<AccountWrapper> accountWrapperList = New List<AccountWrapper>();
List<Account> myAccounts = [Select id, Name, BillingState.
(Select id
From Contacts)
From Account];
if(!myAccounts.isEmpty()){
for(Account currentAccount : myAccounts){
accountWrapperList.add(new AccountWrapper (..) );
}
}
return JSON.serialize(accountWrapperList);
}
Public Class AccountWrapper{
Account currentAccount;
Integer noOfContacts;
Boolean isPartnerAccount;
//Few more variables
Public AccountWrapper(Account currentAccount, Integer noOfContacts, Boolean isPartnerAccount, ..){
this.currentAccount = currentAccount;
....
}
}
}
Let me know if anybody has faced anything similar. Cheers.