You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (Commented) (JIRA)" <de...@myfaces.apache.org> on 2012/03/06 18:48:58 UTC

[jira] [Commented] (MYFACES-3144) [PERF] Cache renderer in UIComponentBase

    [ https://issues.apache.org/jira/browse/MYFACES-3144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13223467#comment-13223467 ] 

Leonardo Uribe commented on MYFACES-3144:
-----------------------------------------

Thinking about it, I found an alternative solution for this problem. The idea is create two vars in UIComponentBase:

    private transient Boolean _cachedIsRendered;
    private transient Renderer _cachedRenderer;

copy the code from UIComponent.encodeAll() to UIComponentBase. Then, do the same trick for cache FacesContext, but on encodeAll(). The idea is set _cachedRendered and _cachedIsRendered at the beginning and then clear this variables before end the method.

Then, some code is added in isRendered() and getRenderer() to check for the cached var and if is set, return that value. In this way we have control about the cached var. If by some reason encodeXXX() is called instead encodeAll(), the code will work as expected. The same thing can be done in decode() method, but in this case only for _cachedRendered, preventing a second call when getClientId() is called.

In this way we can save between 6 and 8 lookups to a map. isRendered() is called only once per component, which is valid because this value does not change while encoding of the same component occur. Also, it preserves getRenderer() plugability, because it is possible to change the renderKit before render response time and reflect the change. 
                
> [PERF] Cache renderer in UIComponentBase
> ----------------------------------------
>
>                 Key: MYFACES-3144
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3144
>             Project: MyFaces Core
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 2.1.0-SNAPSHOT
>         Environment: myfaces core trunk
>            Reporter: Martin Kočí
>            Assignee: Martin Kočí
>         Attachments: MYFACES-3144.patch
>
>
> UIComponentBase uses getRenderer(): Renderer in five methods:
> 1) decode
> 2) encodeBegin
> 3) encodeChildren
> 4) encodeEnd
> 50 getClientId
> getting the renderer is not cheap if you have thousands component in view. 
> Cache renderer instance in UIComponentBase (Trinidad UIXComponentBase does it already)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira