TreeTableView inefficiency
Craig Raw
craigraw at gmail.com
Wed Jul 13 11:31:24 UTC 2022
It appears that my initial email (below) did not make it into the list
archive.
However, I have now found the relevant issue:
https://bugs.openjdk.org/browse/JDK-8280442
I want to note however that the presented workaround of using
getTableRow().isVisible() does not work in general. I find that if one has
a context menu on the cell with an action that causes the TreeTableView to
be hidden, when one returns to the table the display is incorrect with rows
in the wrong place. I have additionally added a check to see if the last
time updateItem was called, it was called with the same TreeTableCell
object, and to avoid any computation if that is the case - this appears to
work.
private static EntryCell lastCell;
@Override
protected void updateItem(Entry entry, boolean empty) {
super.updateItem(entry, empty);
//Return immediately to avoid CPU usage when updating the same
invisible cell to determine tableview size (see
https://bugs.openjdk.org/browse/JDK-8280442)
if(this == lastCell && !getTableRow().isVisible()) {
return;
}
lastCell = this;
//computation....
}
Craig
On Tue, Jul 12, 2022 at 4:34 PM Craig Raw <craigraw at gmail.com> wrote:
> Hi all,
>
> I'm observing behaviour in TreeTableView (and, I assume, TableView) that
> is strange and seems to me to be inefficient for tables with many rows.
>
> On initially displaying the table, the behaviour is as I would expect - a
> number of instances of TreeTableCell objects are created, and updateItem
> is called on them. There are some repeat calls on the same TreeTableCell
> object, but the number of calls is small compared to the number of items in
> the data model.
>
> However, any interaction, however minor, with the scrollbar of the table
> (either user or programmatic) causes updateItem to be called on the same
> TreeTableCell object for every item in the underlying data model. With a
> model with thousands of data rows, this results in several minutes of CPU
> usage doing nothing of apparent use, creating and overwriting the same
> text, graphic, tooltip and contextmenu member variables on the same object
> for each data row.
>
> Once this is completed, the table seems to revert to normal behaviour -
> any new rows that are scrolled into view results in a small number of
> updateItem calls on new TreeTableCell objects commensurate with the
> number of rows revealed.
>
> I have reproduced this on MacOS, Linux and Windows using JavaFX 18.
>
> Is this behaviour expected? If not, are there any workarounds?
>
> Thanks,
> Craig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20220713/bacfa2f2/attachment.htm>
More information about the openjfx-dev
mailing list