Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8311505

Deselection of TableView rows is slow

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 11
      JavaFX 17.0.7 / Java 11.0.19
      JavaFX 20.0.1 / Java 17.0.5

      A DESCRIPTION OF THE PROBLEM :
      For large TableViews (>100000 items) the performance of the deselect operation (TableView.getSelectionModel().clearSelection()) is abysmal. While selecting all items in a 100k list might take 200ms or so, deselecting the items in the list can take ~4 seconds to complete. The delay increases with the number of items to deselect. (500k example is 1.2s to select, 94s to deselect)

      Previously, https://bugs.openjdk.org/browse/JDK-8197991 was posted and has been addressed to greatly improve a similar issue with selecting a large number of items.

      I am able to reproduce the problem on JavaFX 17.0.7 and JavaFX 20.0.1.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Sample code (slightly modified from code provided in JDK-8197991 to add deselection as well) provided that times select all and deselect all for a simple TableView

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Select All and Deselect All operations take about the same time to complete.
      ACTUAL -
      Deselect All operation takes significantly longer to complete; especially noticeable when row count > 100k

      ---------- BEGIN SOURCE ----------
      import static javafx.scene.control.SelectionMode.MULTIPLE;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;


      /**
       * JavaFX App
       */
      public class App extends Application {

      final ObservableList<SimpleObjectProperty<Integer>> listitems = FXCollections.observableArrayList();
      private static int ITEM_COUNT = 500000;

      public App() {
      for (int i = 0; i < ITEM_COUNT; ++i) {
      listitems.add(new SimpleObjectProperty<>(i));
      }
      }

      @Override
      public void start(Stage primaryStage) {
      final TableView<SimpleObjectProperty<Integer>> lv = new TableView<>();
      final TableColumn<SimpleObjectProperty<Integer>, Integer> c = new TableColumn<>();
      c.setCellValueFactory(TableColumn.CellDataFeatures::getValue);
      lv.getColumns().add(c);
      lv.setItems(listitems);

      final HBox hbox = new HBox();
      hbox.getChildren().add(lv);
      primaryStage.setScene(new Scene(hbox));

      lv.getSelectionModel().setSelectionMode(MULTIPLE);

      primaryStage.show();
      Platform.runLater(() -> {
      long startMillis = System.currentTimeMillis();
      lv.getSelectionModel().selectAll();
      System.out.println("Select item count " + ITEM_COUNT + " took " + (System.currentTimeMillis() - startMillis));
      startMillis = System.currentTimeMillis();
      lv.getSelectionModel().clearSelection();
      System.out.println("Deselect item count " + ITEM_COUNT + " took " + (System.currentTimeMillis() - startMillis));
      System.exit(1);
      });
      }

      public static void main(String[] args) {
      Application.launch(args);
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: