我编写了一个 JavaFx 应用程序(JDK 8),它解析一个私有格式的 XML(XML 包含所有形状属性,如坐标、大小、填充、描边等)来构建一个具有大约 4000-5000 个节点布局的场景图根据它们在 SubScene 中的坐标。
每次我打开一个新的私有 XML 时,新的 SubScene 需要延迟 2-3 秒才能显示在我的屏幕上。
我在VM参数中尝试了“-Djavafx.pulseLogger=true”,并在下面显示了记录器,但我不知道如何优化显示时间。我试图强制节点父组没有布局通过,但时间非常长。我还阅读了文章中止如何优化性能中止 Javafx,但我仍然无法正确修复滞后性能。
PULSE: 637 [570ms:1701ms]
T37 (-570 +570ms): Layout Pass
T37 (0 +484ms): CSS Pass
T37 (484 +9ms): Layout Pass
T37 (493 +4ms): Update bounds
T37 (498 +0ms): Waiting for previous rendering
T37 (498 +16ms): Copy state to render graph
T30 (515 +0ms): Dirty Opts Computed
T30 : 2 different dirty regions to render
T30 : Dirty Region 0: RectBounds { minX:406.0, minY:23.0, maxX:440.0, maxY:38.0} (w:34.0, h:15.0)
T30 : Render Root Path 0: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5812bf43, com.sun.javafx.sg.prism.NGRegion@78dbaadd, com.sun.javafx.sg.prism.NGRegion@4a9171aa, com.sun.javafx.sg.prism.NGRegion@1bb83d84, com.sun.javafx.sg.prism.NGRegion@1486dde6]
T30 : Dirty Region 1: RectBounds { minX:0.0, minY:69.0, maxX:1904.0, maxY:1006.0} (w:1904.0, h:937.0)
T30 : Render Root Path 1: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@1cdbe0a1]
T30 (515 +0ms): Render Roots Discovered
T30 : Slow background path for null
T30 (515 +0ms): Painting
T30 : Slow shape path for null
T30 (515 +1185ms): Painting
T30 (1700 +0ms): Presenting
Counters:
CacheFilter rebuilding: 1
Cached region shape image used: 3
NGRegion renderBackgroundShape slow path: 1
NGRegion renderBackgrounds slow path: 1
Nodes rendered: 5384
Nodes visited during render: 7917
Rendering region shape image to cache: 1
PULSE: 638 [1499ms:241ms]
T37 (0 +0ms): CSS Pass
T37 (0 +5ms): Layout Pass
T37 (6 +1ms): Update bounds
T37 (7 +195ms): Waiting for previous rendering
T37 (202 +0ms): Copy state to render graph
T30 (202 +0ms): Dirty Opts Computed
T30 : 4 different dirty regions to render
T30 : Dirty Region 0: RectBounds { minX:6.0, minY:1010.0, maxX:142.0, maxY:1037.0} (w:136.0, h:27.0)
T30 : Render Root Path 0: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5aeb10ed, com.sun.javafx.sg.prism.NGRegion@1e40ff4a]
T30 : Dirty Region 1: RectBounds { minX:294.0, minY:1012.0, maxX:444.0, maxY:1035.0} (w:150.0, h:23.0)
T30 : Render Root Path 1: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5aeb10ed, com.sun.javafx.sg.prism.NGRegion@1e40ff4a]
T30 : Dirty Region 2: RectBounds { minX:470.0, minY:1012.0, maxX:534.0, maxY:1035.0} (w:64.0, h:23.0)
T30 : Render Root Path 2: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5aeb10ed, com.sun.javafx.sg.prism.NGRegion@1e40ff4a]
T30 : Dirty Region 3: RectBounds { minX:6.0, minY:70.0, maxX:128.0, maxY:95.0} (w:122.0, h:25.0)
T30 : Render Root Path 3: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@1cdbe0a1, com.sun.javafx.sg.prism.NGRegion@479f54bb, com.sun.javafx.sg.prism.NGRegion@107cfd69]
T30 (203 +0ms): Render Roots Discovered
T30 : Slow background path for null
T30 : Slow background path for null
T30 (203 +15ms): Painting
T30 (218 +0ms): Painting
T30 (218 +0ms): Painting
T30 (218 +1ms): Painting
T30 (219 +22ms): Presenting
Counters:
Cached region shape image used: 3
NGRegion renderBackgrounds slow path: 2
Nodes rendered: 42
Nodes visited during render: 94
Picture MMI Requset Time Register= local 275 Tue Jun 12 11:46:49 CST 2018
PULSE: 639 [909ms:159ms]
T37 (0 +0ms): CSS Pass
T37 (0 +0ms): Layout Pass
T37 (1 +1ms): Update bounds
T37 (2 +0ms): Waiting for previous rendering
T37 (2 +0ms): Copy state to render graph
T30 (2 +0ms): Dirty Opts Computed
T30 : 4 different dirty regions to render
T30 : Dirty Region 0: RectBounds { minX:6.0, minY:1010.0, maxX:142.0, maxY:1037.0} (w:136.0, h:27.0)
T30 : Render Root Path 0: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5aeb10ed, com.sun.javafx.sg.prism.NGRegion@1e40ff4a]
T30 : Dirty Region 1: RectBounds { minX:294.0, minY:1012.0, maxX:444.0, maxY:1035.0} (w:150.0, h:23.0)
T30 : Render Root Path 1: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5aeb10ed, com.sun.javafx.sg.prism.NGRegion@1e40ff4a]
T30 : Dirty Region 2: RectBounds { minX:470.0, minY:1012.0, maxX:534.0, maxY:1035.0} (w:64.0, h:23.0)
T30 : Render Root Path 2: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@5aeb10ed, com.sun.javafx.sg.prism.NGRegion@1e40ff4a]
T30 : Dirty Region 3: RectBounds { minX:1.0, minY:96.0, maxX:1903.0, maxY:1005.0} (w:1902.0, h:909.0)
T30 : Render Root Path 3: [com.sun.javafx.sg.prism.NGGroup@2734b5a6, com.sun.javafx.sg.prism.NGRegion@2c4e529a, com.sun.javafx.sg.prism.NGRegion@1cdbe0a1, com.sun.javafx.sg.prism.NGRegion@4c1f5ed1, com.sun.javafx.sg.prism.NGRegion@48f39e62]
T30 (2 +0ms): Render Roots Discovered
T30 : Slow background path for null
T30 : Slow background path for null
T30 (2 +0ms): Painting
T30 (3 +0ms): Painting
T30 (3 +0ms): Painting
T30 (3 +155ms): Painting
T30 (158 +0ms): Presenting
Counters:
CacheFilter rebuilding: 1
NGRegion renderBackgrounds slow path: 2
Nodes rendered: 5419
Nodes visited during render: 7994