On Wed, 21 Oct 2026 16:18:33 GMT, Marius Hanl <[email protected]> wrote:

>> Something I found out while experimenting in 
>> https://github.com/openjdk/jfx/pull/2051.
>> It was on my list to do since then.
>> 
>> The `VirtualFlow` can end up creating 1-2 unnecessary cells, which then are 
>> never used. They just sit in the pile.
>> This happens because we may end up calling `addLeadingCells` although our 
>> first cell is already on position `0`, so at the top - there is no cell 
>> above us.
>> 
>> In this scenario, we do not need to call `addLeadingCells`.
>> 
>> Also added the optimization I found in the PR mentioned above.
>> When we have 10 visible cells, size 25px and scroll 10px, we will have 11 
>> cells visible. 
>> If we scroll to the top again, we will have 10 cells visible again -- and in 
>> this case we will remove it from the `sheet`. 
>> But the pile could contain even more piled cells (e.g. when the application 
>> size got smaller, we have less cells to render, all remaining cells went 
>> into the pile). 
>> So the removal is a bit faster with that method, instead of always calling 
>> `removeAll`. Same functionality.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Marius Hanl has updated the pull request with a new target base due to a 
> merge or a rebase. The pull request now contains five commits:
> 
>  - comment
>  - Merge branch 'master' of https://github.com/openjdk/jfx into 
> 8392117-VirtualFlow-may-end-up-creating-1-2-unnecessary-cells
>    
>    # Conflicts:
>    #  
> modules/javafx.controls/src/main/java/javafx/scene/control/skin/VirtualFlow.java
>  - bulk remove
>  - adjust copyright, remove import
>  - 8392117: VirtualFlow may end up creating 1-2 unnecessary cells

modules/javafx.controls/src/main/java/javafx/scene/control/skin/VirtualFlow.java
 line 2874:

> 2872: 
> 2873:         if (removedCells != null) {
> 2874:             sheetChildren.removeAll(removedCells);

we still have a regression: a freshly released cell with index=-1 can be reused 
by a listener (if a listener scrolls, for example).

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/2308#discussion_r4341714717

Reply via email to