Salesforce Blog

Things to consider - Visualforce page performance

Posted by Rajesh

Sep 10, 2014 11:00:33 AM

Things to consider - Visualforce page performance

VisualforceVisualforce was designed to provide developers with the ability to match the functionality, behavior, and performance of standard Salesforce pages. If your users experience delays, unexpected behavior, or other issues specifically around Visualforce, there are several actions you can take to not only improve their experience, but to also make for improved coding.

 

First, determine whether Visualforce is the problem by ensuring that:

  • The problems aren’t confined to a single user’s computer by testing expected Visualforce functionality on other machines as well as using different browsers.
  • Slow load times aren’t the result of a network issue by checking the load time of other Salesforce pages. If they’re also slow, it could be the result of bandwidth or latency issues to Salesforce. To check on the status of the Salesforce servers, visit trust.salesforce.com. You should also check the status of your network connections and ensure they’re functioning properly.
  • You’re following general Web design best practices, such as the minification of JavaScript and CSS, optimizing images for the Web, and avoiding iframes whenever possible.
  • You’ve used the Developer Console to step through the request and determine which items in the request used the most system resources. See “Working with the Developer Console” in the Salesforce online help.

The following is a list of commonly encountered Visualforce performance issues and their possible solutions:

 

View State Size

The view state size of your Visualforce pages must be under 135KB. By reducing your view state size, your pages can load quicker and stall less often. You can monitor view state performance through the View State tab in the development mode footer and take the following actions:

  • Use the transient keyword in your Apex controllers for variables that aren’t essential for maintaining state and aren’t necessary during page refreshes.
  • If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.
  • If your view state is affected by a large component tree, try reducing the number of components your page depends on.

 

Load Times

Large page sizes directly affects load times. To improve Visualforce page load times:

  • Cache any data that is frequently accessed, such as icon graphics
  • Avoid SOQL queries in your Apex controller getter methods
  • Reduce the number of records displayed on a page by:
  • Lazy load” Apex objects to reduce request times
  • Consider moving any JavaScript outside of the <apex:includeScript> tag and placing it into a <script> tag right before your closing <apex:page> tag. The <apex:includeScript> tag places JavaScript right before the closing <head> element; thus, Visualforce attempts to load the JavaScript before any other content on the page. However, you should only move JavaScript to the bottom of the page if you're certain it doesn't have any adverse effects to your page. For example, JavaScript code snippets requiring document.write or event handlers should remain in the <head> element.

In all cases Visualforce pages must be under 15 MB.

 

Multiple Concurrent Requests

Concurrent requests are long running tasks that could block other pending tasks. To reduce these delays:

  • Action methods used by <apex:actionPoller> should be lightweight. It's a best practice to avoid performing DML, external service calls, and other resource-intensive operations in action methods called by an <apex:actionPoller>. Carefully consider the effect of your action method being called repeatedly by an <apex:actionPoller> at the interval you specify, especially if it's used on a page that will be widely distributed, or open continuously.
  • Increase the time interval for calling Apex from your Visualforce page. For example, when using the <apex:actionPoller> component, you could adjust the interval attribute to 30 seconds instead of 15.
  • Move non-essential logic to an asynchronous code block using Ajax.

 

Queries and Security

By using the with sharing keyword when creating your Apex controllers, you have the possibility of improving your SOQL queries by only viewing a data set for a single user.

 

Preventing Field Values from Dropping off the Page

If your page contains many fields, including large text area fields, and has master-detail relationships with other entities, it may not display all data due to limits on the size of data returned to Visualforce pages and batch limits. The page displays this warning: “You requested too many fields to display. Consider removing some to prevent field values from being dropped from the display.” To prevent field values from being dropped from the page, remove some fields to reduce the amount of data returned. Alternatively, you can write your own controller extensions to query child records to be displayed in the related lists.

 

Check out our previous post on preventing hackers using SOQL injection.

 

Click the button below to have your Salesforce Questions answered.

Salesforce Questions

 

To submit comments on this post use the form below: