0

I was hoping someone could help explain what happens when ActionFunction gets triggered that could cause the slowness that I see here:
https://developer.salesforce.com/forums/ForumsMain?id=9060G000000I73LQAS

I noticed unusual slowness in my ActionFunction calls, so set up the simple test shown below. It should just call 'actionFunctionTest' 5 times, which itself does not have an action, has immediate=true, and rerender=none.

As is, it takes 4-10 seconds to complete.
If I remove controller="TestClass", just leaving apex:page at the top, it only takes 600ms to complete. ... though even this is slower than I would hope for.

I have not included TestClass, but was hoping someone could explain at a high level what is happening here. Is this expected behaviour? Why does the TestClass have any impact on the timing of this, given that nothing in the class is being referenced or rerendered (at least not intentionally)? Are there any other flags that I can set to ensure that the actionfunction will be a nearly instantaneous call to the javascript function?

Note - in reality, I am using several actionFunctions to perform simple tasks like rerendering messages, and I would like to be able to do this without the overhead of whatever else is happening.

<apex:page controller="TestClass">
<script>
    var startTime;
    var counter;
    javascriptHelper = function(init) {
        if( init ) {
            startTime = new Date().getTime();
            counter = 0;
            actionFunctionTest();
        } else if( counter < 5 ) {
            counter++;
            actionFunctionTest();
        } else {
            endTime = new Date().getTime();
            alert( 'Total Time: ' + (endTime-startTime) );
        }
    }
</script>
<apex:form >
    <apex:commandButton value="Test actionFunction Speed" immediate="true" oncomplete="javascriptHelper(true);return false;" rerender="none"/>
    <apex:actionFunction name="actionFunctionTest" immediate="true" oncomplete="javascriptHelper(false);return false;" rerender="none"/>
</apex:form>

1

This time is spent serializing/deserializing the view state.

This involves a loop to the server and back when the form is submitted.

When you remove the class, Visualforce knows there cannot be a view state and so nothing is ever submitted.

For the purposes you listed, there are a bunch of options.

  • The simplest is to not use a commandbutton and just use a regular button. Commandbutton is what submits the form.
  • Use javascript remoting
  • Use commandButton outside of form

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.