Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3487

[perf] cache unique ids generated by facelets

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.0.13, 2.1.7
    • JSR-314
    • None

    Description

      It could be good to cache unique ids and reduce the impact in memory such generation has in memory. It is possible to cache:

      1. The generated unique ids at level 0 per view. If the view is not dinamic the generated list will always be the same, but it will change per view. The ideal is store it in a volatile field.
      2. The component unique ids passed to generate later an unique id in UniqueIdVendor.createUniqueId(). By the spec it is not possible to hook createUniqueId, but we can reuse for that counter the generated values "at level 0" (which means for components that are not in a dynamic part).

      It is possible to use FaceletCompositionContext.startComponentUniqueIdSection(), to indicate the "level 0" where all unique ids will be generated whithout change.

      The cache proposed in 2. can be enabled by default, because it is something more related to the counter, but the cache for 1. it is too risky. I tried by default and it pass all tests, but for now I'll let it by default false to prevent problems.

      The proposal is add these two params:

      /**

      • Enable or disable a cache used to "remember" the generated facelets unique ids and reduce
      • the impact on memory usage, only active if javax.faces.FACELETS_REFRESH_PERIOD is -1 (no refresh).
        */
        @JSFWebConfigParam(defaultValue = "false", since = "2.0.13, 2.1.7", expectedValues="true, false",
        group="viewhandler", tags="performance",
        desc="Enable or disable a cache used to 'remember' the generated facelets unique ids " +
        "and reduce the impact over memory usage.")
        public static final String INIT_PARAM_VIEW_UNIQUE_IDS_CACHE_ENABLED =
        "org.apache.myfaces.VIEW_UNIQUE_IDS_CACHE_ENABLED";
        public static final boolean INIT_PARAM_VIEW_UNIQUE_IDS_CACHE_ENABLED_DEFAULT = false;

      /**

      • Set the size of the cache used to store strings generated using SectionUniqueIdCounter
      • for component ids. If this is set to 0, no cache is used. By default is set to 100.
        */
        @JSFWebConfigParam(defaultValue = "100", since = "2.0.13, 2.1.7",
        group="viewhandler", tags="performance")
        public static final String INIT_PARAM_COMPONENT_UNIQUE_IDS_CACHE_SIZE =
        "org.apache.myfaces.COMPONENT_UNIQUE_IDS_CACHE_SIZE";
        public static final int INIT_PARAM_COMPONENT_UNIQUE_IDS_CACHE_SIZE_DEFAULT = 100;

      If no objections I'll commit the solution proposed soon.

      Attachments

        1. MYFACES-3487-1.patch
          24 kB
          Leonardo Uribe

        Activity

          People

            lu4242 Leonardo Uribe
            lu4242 Leonardo Uribe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: