I have an LWC page with three section getting data from 3 apex methods all are returning a list of wrapper class, my requirement is lesser initial load time of the page, to fetch data from apex I have two approaches in my mind.

  1. Use 3 wire methods to fetch data from 3 apex methods.
  2. Create one common method in apex to call other methods and return only one object of wrapper class with 3 list type properties of other wrapper classes and use only one wire method in JS to call data from apex

if I use first approach then all wire methods fetch data in three apex contexts and in 2nd approach it will fetch data only in one apex context.

In my case I am sure I won't hit the governor limit if I use 2nd approach but is there any other things to consider and also which approach will take more time to load?


Both methods will take (approximately) the same amount of time to load. In fact, the "three method" approach may even be faster than using just one method. Unlike Aura, LWC can leverage multiple threads (up to six) to fetch data from the server. All things being equal, this means that there will be some performance gain as threads can overlap each other, while Apex cannot execute in parallel in the same thread.

If you want faster performance, your only real choice is to figure out a way to either optimize the CPU time or bandwidth used. This can mean things like making sure you're using efficient loops (avoiding nested loops), querying only the fields and records you need to do your processing, etc. Consolidating your calls into one, at best, will have no appreciable effect, and in some cases, may worsen load times.

  • Thank you, I will stick to first approach then – gs650x Mar 29 '20 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.