title: JavaFX slow performance on canvas when drawing freestyle with pen
body: <p>I was trying out the code here for making a JavaFX app which allows my stylus pen to draw on a canvas: <a href="https://stackoverflow.com/questions/16816558/canvas-does-not-draw-smooth-lines">Canvas does not draw smooth lines</a></p>
  
  <p>The performance is extremely painful when trying to draw on a canvas. It will freeze for half a second, and then start drawing. Only after it starts drawing is it fine. Beforehand though when you first press down with the mouse/pen, the delay is pretty brutal and makes it unusable.</p>
  
  <p>Here is the code I used:</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.canvas.Canvas;
  import javafx.scene.canvas.GraphicsContext;
  import javafx.scene.effect.BoxBlur;
  import javafx.scene.shape.StrokeLineCap;
  import javafx.scene.shape.StrokeLineJoin;
  import javafx.stage.Stage;
  
  public class Test extends Application {
  
      private GraphicsContext gc;
  
      @Override
      public void start(Stage stage) {
          Canvas canvas = new Canvas(500, 500);
          canvas.setOnMouseDragged(e -&gt; {
              gc.lineTo(e.getX(), e.getY());
              gc.stroke();
          });
          canvas.setOnMousePressed(e -&gt; gc.moveTo(e.getX(), e.getY()));
  
          gc = canvas.getGraphicsContext2D();
          gc.setLineCap(StrokeLineCap.ROUND);
          gc.setLineJoin(StrokeLineJoin.ROUND);
          gc.setLineWidth(1);
  
          BoxBlur blur = new BoxBlur();
          blur.setWidth(1);
          blur.setHeight(1);
          blur.setIterations(1);
          gc.setEffect(blur);
  
          Group root = new Group(canvas);
          Scene scene = new Scene(root);
          stage.setScene(scene);
          stage.show();
          stage.setFullScreen(true);
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Is there any way to fix the performance issue? My desktop computer is pretty solid and can run high-end games, so its not the performance on my computer.</p>
  
  <p>NOTE: I should also say that the delay that occurs when you first press the mouse on the canvas is bad enough to cause mouse clicks to drop.</p>
  
  <p>EDIT: To confirm it wasnt the OnMousePressed, I commented it out and it did not help.</p>