Wiki » Java » JavaFX » JavaFXとベクターグラフィックス »
JavaFX ライン描画をCanvasとシーングラフとで比較¶
JavaFXで微小ラインを大量に描く場合の性能を2つの実装方法で比較しました。
- Canvasでラインを描画
- シーングラフにラインを追加して描画
ラインは500×500個で長さは1.4です。
pulseLoggerで表示される値を比較します。
結果¶
pulseLogger出力¶
Canvasを使った場合¶
PULSE: 16 [4967ms:291ms] T12 (0 +0ms): CSS Pass T12 (0 +0ms): Layout Pass T12 (0 +0ms): Waiting for previous rendering T12 (0 +0ms): Copy state to render graph T10 (1 +0ms): Dirty Opts Computed T10 (1 +0ms): Render Roots Discovered T10 : 2 different dirty regions to render T10 : Dirty Region 0: RectBounds { minX:0.0, minY:0.0, maxX:500.0, maxY:500.0} (w:500.0, h:500.0) T10 : Render Root Path 0: [com.sun.javafx.sg.prism.NGRegion@686631b9] T10 : Dirty Region 1: RectBounds { minX:514.0, minY:417.0, maxX:594.0, maxY:446.0} (w:80.0, h:29.0) T10 : Render Root Path 1: [com.sun.javafx.sg.prism.NGRegion@686631b9] T10 (1 +287ms): Painted T10 (288 +0ms): Painted T10 (288 +3ms): Presentable.present T10 (291 +0ms): Finished Presenting Painter Counters: Cached region background image used: 1 Nodes rendered: 7 Nodes visited during render: 13
シーングラフにラインを追加の場合¶
PULSE: 23 [5273ms:296ms] T12 (1 +1ms): CSS Pass T12 (2 +0ms): Layout Pass T12 (2 +0ms): Waiting for previous rendering T12 (2 +0ms): Copy state to render graph T10 (2 +1ms): Dirty Opts Computed T10 (3 +0ms): Render Roots Discovered T10 : 2 different dirty regions to render T10 : Dirty Region 0: RectBounds { minX:0.0, minY:0.0, maxX:500.0, maxY:500.0} (w:500.0, h:500.0) T10 : Render Root Path 0: [com.sun.javafx.sg.prism.NGRegion@628c14ec] T10 : Dirty Region 1: RectBounds { minX:514.0, minY:417.0, maxX:594.0, maxY:446.0} (w:80.0, h:29.0) T10 : Render Root Path 1: [com.sun.javafx.sg.prism.NGRegion@628c14ec] T10 (3 +288ms): Painted T10 : Slow background path for null T10 : Slow background path for null T10 : Slow background path for null T10 : Slow background path for null T10 : Slow background path for null T10 (291 +2ms): Painted T10 (293 +3ms): Presentable.present T10 (296 +0ms): Finished Presenting Painter Counters: Cached region background image used: 1 NGRegion renderBackgrounds slow path: 5 Nodes rendered: 7 Nodes visited during render: 13 Rendering region background image to cache: 1
プログラム¶
Canvasを使ったコード(抜粋)¶
@FXML
private Canvas canvas;
:
@FXML
public void drawLines(ActionEvent ev) {
GraphicsContext gc = canvas.getGraphicsContext2D();
Random rand = new Random();
for (int i = 0; i < 500; i++) {
for (int j = 0; j < 500; j++) {
int type = rand.nextInt(4);
gc.setStroke(PAINTS[type]);
gc.strokeLine(i, j, i + DELTAS[type].getX(), j + DELTAS[type].getY());
}
}
}
シーングラフにラインを追加したコード(抜粋)¶
@FXML
private Pane pane;
:
@FXML
public void drawLines(ActionEvent ev) {
Random rand = new Random();
List<Node> lines = new ArrayList<>(250000);
for (int i = 0; i < 500; i++) {
for (int j = 0; j < 500; j++) {
int type = rand.nextInt(4);
Line line = new Line(i, j, i + DELTAS[type].getX(), j + DELTAS[type].getY());
line.setStroke(PAINTS[type]);
lines.add(line);
}
}
pane.getChildren().addAll(lines);
}
10年以上前に更新