myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rapster (JIRA)" <>
Subject [jira] [Commented] (MYFACES-3130) [perf] Avoid unnecessary AbstractList$Itr instances
Date Sun, 02 Sep 2018 10:09:00 GMT


Rapster commented on MYFACES-3130:

[~markoc50] I think using foreach loop is the way to go as long the unlerlying call does
not involve recursive call or sucession of loops (as it will overstock the stack memory and
the heap, the reason of your issue actually). Basically, something like this IMO is not necessary:

 for (int i = 0; i < childCount; i++)
      UIComponent child = component.getChildren().get(i);
      if (!child.isTransient())

_markInitialState is only a setter call, so no risk to overtsock the heap. On the other hand,
this sample makes perfectly sense

for (int i = 0; i < childCount; i++)
    UIComponent child = getChildren().get(i);
    if (child.visitTree(context, callback))
        return true;

UIViewRoot#visitTree implies components visitTree calls, which can lead to snowball effect
so better to avoid creation of iterator as it can be quickly huge.

I'm just sharing my thought, 'cause foreach is the recommended way to go, there are of course
few exceptionnal cases

> [perf] Avoid unnecessary AbstractList$Itr instances
> ---------------------------------------------------
>                 Key: MYFACES-3130
>                 URL:
>             Project: MyFaces Core
>          Issue Type: Improvement
>          Components: JSR-314
>         Environment: myfaces core trunk
>            Reporter: Martin Kočí
>            Assignee: Thomas Andraschko
>            Priority: Major
>             Fix For: 2.3.0
>         Attachments: MYFACES-3130-example.patch, MYFACES-3130-part2.patch, UIViewRoot-MYFACES-3130.patch
> Similar issue: MYFACES-3129
> loop from java 5:
> for (Object object: objects)
> creates new instance of AbstractList$Itr, if objects are instance of ArrayList. 
> Similar situation is with explicit .iterator() call.
> In my testcases, it is about ~ 100 000 instances per request/response. Creation itself
is cheap, but triggers GC lately.
> I suggest to use old index-style for (i = 0; i < childCount;   i++) if possible. Are
there any rawbacks of index-based iteration? 
> Children is List and as implementation detail we  know that it is instance of ArrayList.

This message was sent by Atlassian JIRA

View raw message