chrosciu
chrosciu

Reputation: 304

JSF ajax performance issue when using a lot of components

I use Mojarra implementation of JSF (version 2.2.1). I have a big problem with performance during ajax requests.

My page has a lot of components so I understand why first rendering takes much time, but what with ajax requests?

They takes also a lot of time although they do almost nothing. Here is my simplified example:

In below example pressing "performance test" button takes several ms:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:body>
        Hello World
        <h:form>
            <h:commandButton value="performance test">
                <f:ajax execute="@this" render="@none" />
            </h:commandButton>
        </h:form>
    </h:body>
 </html>

But if add 1000 <h:inputText /> elements to the <h:form></h:form> the same action takes over 100ms !

I have checked that 80% of time is consumed in RESTORE_VIEW phase, 20 % in RENDER_RESPONSE phase, rest of phases do not take significant amount of time.

Is there any possibility to fix it?

I tried also to disable javax.faces.PARTIAL_STATE_SAVING (memory consumption is not the problem in my case) but also without any success.

EDIT: A thousand of <h:inputText> added to a <h:form> was only a simplified example. I just wanted to emphasize the fact that big amount of components has significant influence on the ajax request (that does almost nothing) - which is a severe problem on my website.

In the reality, of course, I don't have 1000 inputs. I display very big table with a lot of data - if data is empty in any cell there should by an hyphen instead. I used composite component for that - where I had more than one ui:fragment with render=true/false

Today I tried to use my own component instead of composite one - and response time and memory usage have decreased.

But I'm still not satisfied because my very simple ajax request on that page takes much more time than the same ajax request used on another - thinner page (i.e. with less number of components). Isn't it any JSF architecture issue?

Upvotes: 2

Views: 3125

Answers (1)

mrembisz
mrembisz

Reputation: 12880

Not really, JSF always rebuilds the entire component tree in restore view phase. You would do better with <ui:repeat> in this case but I realize your test is artificial and real page could have a lot of unique components.

There are quite a few ways to reduce the amount of components, like mentioned <ui:repeat>. Also you can use plain html in your facelets. Chunks of html free of JSF tags are represented as a single UIInstructions component. Still you can use EL expressions in there. It is hard to recommend something particular without more details of your problematic scenario.

EDIT: Component tree is restored top-bottom, no idea whether it's feasible to somehow optimize it and skip parts not needed by a request. The problem is you don't know in which part of the component tree nodes with particular id specified in ajax tag would be, you can only attempt some optimizations. Looks like the authors did not consider these complications worth the effort.

As for multiple conditional sections - I haven't found anything directly supporting this in JSF. A dedicated custom component sounds like the best bet here. We did something similar, our own implementation of <ui:include>, which supports dynamic src attribute working inside <ui:repeat>.

Upvotes: 1

Related Questions