[MAGNOLIA-7030] Optimise the usage of AnnotationUtils class Created: 17/May/17  Updated: 12/Mar/23

Status: Open
Project: Magnolia
Component/s: None
Affects Version/s: 5.5.4
Fix Version/s: None

Type: New Feature Priority: Neutral
Reporter: Aleksandr Pchelintcev Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: config, i18n
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
Template:
Acceptance criteria:
Empty
Team: Nucleus

 Description   

AnnotationUtils is primarily used by i18n mechanism in order to identify translatable getters and types. Used in conjunction with ProxyToys interceptors AnnotationUtils conducts the look up whether a method has the annotation applied to it. This means that *every i18n-ed definition method call* results into:

  • class hierarchy look-up (we need to get all the parent types and all method implementations and check whether any of them has annotation applied).
  • multiple class/method annotation look-up
  • since Reflections library is used to look-up/filter the annotations, some collections and other garbage objects are created on the way (we are still talking about a getter call!)

Load tests have shown that these reflective operations due to their high amount tend to consume a lot of CPU.

Easiest way to mitigate the issue is to cache the results of the look-ups:

  • cache class hierarchies
  • cache the method/type annotations
    Experiments have proved that this renders the resource consumption by AnnotationUtils to minimum.

Potential follow-up:

  • it still seems that rather frequent I18N-ization calls in UI are causing *some* resource waste (nothing compared to above but still). This is related to CGLIB bytecode transformations being involved in the process (heavy!). The suggestion here is to consider i18n-ed API for the definition provider. I.e. besides of DefinitionProvider#get() we could also have DefinitionProvider#getLocalised() which will produce an i18n-ised proxy once (until the underlying config changes of course).

Generated at Mon Feb 12 04:20:05 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.