How to efficiently profile Visualforce components and their controllers?

I have a quite complex Visualforce component (edit grid) that is running to slow (2-4 seconds to display)
When I say complex I mean:

  • The Component itself is calling other components
  • Many thousand lines of code
  • Using StandardSetController to work and display arbitrary record numbers
  • Reading and writing records and Custom Settings
  • Lot of Schema querying

I am not a newbie so I incorporated all know best practices regarding performant Apex and VF code. As this still results in a poor performance I tried to do some profiling (log file analysis to find out what takes to long and why. But none of the tools I tried really allowed this:

  1. Developer console

    • Terrible slow interface in FF and Chrome
    • Timeline view and Performance Tree to coarse
  2. External Logging with http://loggly.com/

    • As this requires callouts and future methods can’t be used in a Visualforce get/set and constructors. But those are critical.
  3. Adding and analysing my own System.debug()

    • As the regular log is already quite big, Salesforce.com seems to strip out all my custom DEBUG lines.

SOS! What other alternatives are there? What do you / did you do in such cases?!

Answer

Other Tools. Your tools list is a good one, as is your question! In addition I would recommend you take a look at the Viewstate contents via the ‘Show Viewstate in Developer Mode‘ setting on your user. This enables the following view on your page. Note that you can use ‘transient’ to control this for information you define in your controller that is essentially request scope only (not needed to be retained next time round). The research done here also proves that overuse of VF components, especially in large list rendering scenarios can cause the ‘internal’ view state to grow, so watch out for this as well.

enter image description here

Best Practice for Performance in VF

  • Monitor the size of your view state. Use the transient modifier where you can. Large Viewstates take a long time to serialise and deserialise and are known to impact page load, save and VF AJAX interactions (not JavaScript Remoting see below) under large volumes (see below for particular sensitive scenarios).
  • Using VF components in large tables/repeats, each VF component e.g. apex:inputField carries quite a lot of internal view state baggage and to some degree HTML output. So keep an eye on this and use pagination where you can / users tolerate.
  • Try to control the scope of your rerender attributes if you are using VF AJAX features such as apex:actionSupport and apex:actionFunction.
  • Consider using JavaScript Remoting, this is a shift in development style, as you loose automatic management of your pages state. Effectively pushing the state in the browser. However the speed benifits are significant. Though you do need of course more JavaScript skills.
  • Mix and Match. You can btw, mix the use of traditional VF Components / Bindings / AJAX (as per above) and JavaScript Remoting. So this maybe an option for events that your performing currently that don’t actually update the state more refresh or default things on your page. Or for example use only VF viewstate for load and save of the page and for all tab out/AJAX stuff utilise Java Script Remoting. Of course while this will help with interaction once the page loads, it won’t help address page load times necessarily, though may if in implementing it, it helps reduce your viewstate. Mix and Match approach is really only helpfully if your migrating and/or have limited coding time, I would not recommend it as a best practice from scratch necessarily.

Attribution
Source : Link , Question Author : Robert Sösemann , Answer Author : Community

Leave a Comment