https://bugs.openjdk.org/browse/JDK-8355986

On 4/30/2025 9:05 AM, Andy Goryachev wrote:

Thank you, Pavel, for filing the ticket (it will take some time before it gets routed to me).  And thank you so much for the feedback - keep it going!

-andy

*From: *openjfx-dev <openjfx-dev-r...@openjdk.org> on behalf of PavelTurk <pavelturk2...@gmail.com>
*Date: *Wednesday, April 30, 2025 at 08:54
*To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
*Subject: *Re: CodeArea: too frequent model updates

Hello, Andy

I've made sure to formulate everything very precisely and just created a new issue. Unfortunately I know only its ID: 9078451.

If my proposal is incorrect - then this issue is not meant to be resolved. However, I'm certain this is an important question regardless.

Best regards, Pavel

On 4/30/25 17:45, Andy Goryachev wrote:

    Dear Pavel:

    As I mentioned before, the view might request more paragraphs than
    currently visible, so it works as designed.

    When you say it's slow, could you tell what metric / measurement
    you used?  The attached code does not appear slow on my macOS. 
    Would you provide a reproducer which can illustrate the issue?

    Thanks

    -andy

    *From: *openjfx-dev <openjfx-dev-r...@openjdk.org>
    <mailto:openjfx-dev-r...@openjdk.org> on behalf of PavelTurk
    <pavelturk2...@gmail.com> <mailto:pavelturk2...@gmail.com>
    *Date: *Wednesday, April 30, 2025 at 04:14
    *To: *openjfx-dev@openjdk.org <openjfx-dev@openjdk.org>
    <mailto:openjfx-dev@openjdk.org>
    *Subject: *CodeArea: too frequent model updates

    Trying to understand why my Jfx CodeArea works so slowly I wrote a
    test application (see below).
    And I got interesting results. If you start the application you
    will see that about 10 paragraphs
    are visible.

    1. If after start you click on the report button you will see that
    about 113 paragraphs were created (remember 10 visible).
    2. If you click event button (as I understand to update only 15
    paragraphs - I can be wrong here) in the report you will see 112
    paragraphs.
    3. If you scroll to line 100, click report to clear, add one
    letter via keyboard and in the new report you will see 210
    paragraphs were updated.
    So, with one paragraph modified and 10 paragraphs visible CodeArea
    updates 210 paragraphs.

    I see two solutions here:
    1) If Jfx CodeArea wants to update paragraphs itself it should be
    optimized
    2) A better solution is to remove final modifier from
    CodeTextModel.getParagraph(int index) method so that we could
    override it.

    public class JfxTextArea extends Application {

         @Override
         public void start(Stage primaryStage) throws Exception {
             CodeArea codeArea = new CodeArea();
    codeArea.setLineNumbersEnabled(true);
             final List<Integer> requestedIndexes = new ArrayList<>();
             codeArea.setSyntaxDecorator(new SyntaxDecorator() {
                 @Override
                 public RichParagraph
    createRichParagraph(CodeTextModel ctm, int i) {
                     requestedIndexes.add(i);
                     RichParagraph.Builder b = RichParagraph.builder();
    b.addSegment(ctm.getPlainText(i));
                     return b.build();
                 }

                 @Override
                 public void handleChange(CodeTextModel ctm, TextPos
    tp, TextPos tp1, int i, int i1, int i2) {

                 }
             });
             StringBuilder sb = new StringBuilder();
             for (var i = 0; i < 1000; i++) {
                 sb.append(i);
                 sb.append("\n");
             }
             codeArea.setText(sb.toString());

             var reportButton = new Button("Report & Clear");
             reportButton.setOnAction(e -> {
    Collections.sort(requestedIndexes);
    System.out.println("Created/Updated " + requestedIndexes.size() +
    " paragraphs: " + requestedIndexes);
                 requestedIndexes.clear();
             });
             var topButton = new Button("To Top");
             topButton.setOnAction(e -> codeArea.select(new TextPos(0,
    0, 0, true)));
             var bottomButton = new Button("To Bottom");
             bottomButton.setOnAction(e -> codeArea.select(new
    TextPos(999, 0, 0, true)));
             var eventButton = new Button("Fire Event");
             eventButton.setOnAction(e -> codeArea.getModel()
                     .fireStyleChangeEvent(new TextPos(0, 0, 0, true),
    new TextPos(15, 0, 0, true)));
             HBox buttonBox = new HBox(reportButton, topButton,
    bottomButton, eventButton);

             VBox.setVgrow(codeArea, Priority.ALWAYS);
             VBox root = new VBox(codeArea, buttonBox);
             Scene scene = new Scene(root, 600, 200);
             primaryStage.setScene(scene);
             primaryStage.show();

         }

         public static void main(String[] args) {
             launch(args);
         }

    }

    Best regards, Pavel

Reply via email to