function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Benjamin KassBenjamin Kass 

ActionFunction Slowness

I noticed unusual slowness in my ActionFunction calls, so set up the following simple test. 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>
</apex:page>