You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@juneau.apache.org by James Bognar <ja...@apache.org> on 2023/06/26 15:23:01 UTC

Juneau code refactoring.

Thanks for cleaning up this code!  Everything looks great.  The only
concern is refactoring the following into for-in-loops:

for (int i = 0; i < list.length(); i++) {
   Object o = list.get(i);
}

When you see that pattern, it's usually in a high-performance block and
it's against an array list and I'm trying to avoid an Iterator object
creation.

Refactoring the following into for-in-loops is fine though since it
compiles identically....

for (int i = 0; i < array.length; i++) {
   Object o = array[i];
}

Re: Juneau code refactoring.

Posted by James Bognar <ja...@apache.org>.
Hi Gary,

Yes, please revert the for-each loops over collections.  I would have only
used that pattern if it was a particularly performance-sensitive part of
the code and found that it did in fact have a small effect.

Thanks!  And please feel free to continue refactoring.  This code
originated on Java 5 so there is definitely some old patterns around.

On Mon, Jun 26, 2023 at 8:52 PM Gary Gregory <ga...@gmail.com> wrote:

> Hi James,
>
> I think I've reviewed all your comments, thank you for the thorough
> review. I believe we've sync'd up on everything except the following.
>
> I have 3 commits that are now candidates for reverting related to your
> concern on using for-each loops on Collections (as opposed to arrays).
>
> I can imagine that performance could be affected in some cases, maybe, but
> I really don't think we would see the difference in any kind of user test.
> I prefer the lower cognitive load (for me). That said, I want to confirm
> that you really want these call sites changed back before I take the time
> to do so.
>
> TY!
> Gary
>
> On Mon, Jun 26, 2023, 11:23 James Bognar <ja...@apache.org> wrote:
>
>> Thanks for cleaning up this code!  Everything looks great.  The only
>> concern is refactoring the following into for-in-loops:
>>
>> for (int i = 0; i < list.length(); i++) {
>>    Object o = list.get(i);
>> }
>>
>> When you see that pattern, it's usually in a high-performance block and
>> it's against an array list and I'm trying to avoid an Iterator object
>> creation.
>>
>> Refactoring the following into for-in-loops is fine though since it
>> compiles identically....
>>
>> for (int i = 0; i < array.length; i++) {
>>    Object o = array[i];
>> }
>>
>>
>>

Re: Juneau code refactoring.

Posted by Gary Gregory <ga...@gmail.com>.
Hi James,

I think I've reviewed all your comments, thank you for the thorough review.
I believe we've sync'd up on everything except the following.

I have 3 commits that are now candidates for reverting related to your
concern on using for-each loops on Collections (as opposed to arrays).

I can imagine that performance could be affected in some cases, maybe, but
I really don't think we would see the difference in any kind of user test.
I prefer the lower cognitive load (for me). That said, I want to confirm
that you really want these call sites changed back before I take the time
to do so.

TY!
Gary

On Mon, Jun 26, 2023, 11:23 James Bognar <ja...@apache.org> wrote:

> Thanks for cleaning up this code!  Everything looks great.  The only
> concern is refactoring the following into for-in-loops:
>
> for (int i = 0; i < list.length(); i++) {
>    Object o = list.get(i);
> }
>
> When you see that pattern, it's usually in a high-performance block and
> it's against an array list and I'm trying to avoid an Iterator object
> creation.
>
> Refactoring the following into for-in-loops is fine though since it
> compiles identically....
>
> for (int i = 0; i < array.length; i++) {
>    Object o = array[i];
> }
>
>
>