Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Performance issue with FXCanvas
Performance issue with FXCanvas [message #1388294] Thu, 26 June 2014 08:21 Go to next message
Michał Ćmil is currently offline Michał ĆmilFriend
Messages: 4
Registered: March 2014
Junior Member
Hello,

I tried to run FlexGanttFX in an E4 application (using an FXCanvas) and I've noticed that the performance is lower than when running a standalone JavaFX application. That made me wondering if its specific to the things I do, or its a more general problem. I made a little benchmark using Oracle samples. I've run the same code (thousands of colorful circles drawn on a 1080p scene) using FXCanvas and in a standalone JavaFX application (the code is available on github.com: mcmil/fxcanvas-benchmark). The results are as follows (values are FPS measured by Performance tracker):
standalone javafx app
Avg: 0.0 instant 0.0
Avg: 34.598766 instant 0.0
Avg: 45.718437 instant 36.872547
Avg: 49.234116 instant 55.55428
Avg: 50.958836 instant 56.874763
Avg: 51.982483 instant 55.835545
Avg: 52.82121 instant 54.849483
Avg: 49.67068 instant 57.75312
Avg: 43.40379 instant 57.75312

FXCanvas
Avg: 0.0 instant 0.0
Avg: 19.496336 instant 0.0
Avg: 23.803656 instant 19.982939
Avg: 25.214998 instant 27.849215
Avg: 25.412786 instant 27.835789
Avg: 25.731888 instant 26.75477
Avg: 26.278933 instant 26.842173
Avg: 23.945173 instant 28.574305
Avg: 20.942469 instant 28.574305


As you can see I got around 50% frame drop. But the problem is that the drop is really noticeable for the end user. I went to investigate the FXCanvas class, and saw something like this in it:
 // Consider optimizing this
        ImageData imageData = null;
        if ("win32".equals(SWT.getPlatform())) {
            PaletteData palette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
            int scanline = width * 4;
            byte[] dstData = new byte[scanline * height];
            int[] srcData = buffer.array();
            int dp = 0, sp = 0;
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int p = srcData[sp++];
                    dstData[dp++] = (byte) (p & 0xFF); //dst:blue
                    dstData[dp++] = (byte)((p >> 8) & 0xFF); //dst:green
                    dstData[dp++] = (byte)((p >> 16) & 0xFF); //dst:green
                    dstData[dp++] = (byte)0x00; //alpha
                }
            }
            /*ImageData*/ imageData = new ImageData(width, height, 32, palette, 4, dstData);
}


Well, that looks bad. But even when I removed this looping - the performance gain was not that big. So the problem is somewhere else.

My question is: is there any way to embed an JavaFX scene inside of an SWT application (E4) without such a performance drop? Will it get optimized in further JDK versions or it is unknown? Or maybe there are some optimization techniques that I can use for SWT to avoid this issues?

Any advice would be great - because currently, the performance is quite a problem.

Re: Performance issue with FXCanvas [message #1388305 is a reply to message #1388294] Thu, 26 June 2014 08:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You better direct your questions towards Oracle - we do not maintain
that code! If I understand FXCanvas appropriately it renderes JavaFX
into an offscreen buffer and copies the pixels back and draws them on
the SWT-Canvas.

In the log run I think you are better of switching your e4 application
fully towards JavaFX, in case you have SWT-UI-Code our SWT on JavaFX
port might help you, it is able to render most buisness UIs.

Tom

On 26.06.14 10:21, Michał Ćmil wrote:
> Hello,
>
> I tried to run FlexGanttFX in an E4 application (using an FXCanvas) and
> I've noticed that the performance is lower than when running a
> standalone JavaFX application. That made me wondering if its specific to
> the things I do, or its a more general problem. I made a little
> benchmark using Oracle samples. I've run the same code (thousands of
> colorful circles drawn on a 1080p scene) using FXCanvas and in a
> standalone JavaFX application (the code is available on github.com:
> mcmil/fxcanvas-benchmark). The results are as follows (values are FPS
> measured by Performance tracker):
> standalone javafx app
> Avg: 0.0 instant 0.0
> Avg: 34.598766 instant 0.0
> Avg: 45.718437 instant 36.872547
> Avg: 49.234116 instant 55.55428
> Avg: 50.958836 instant 56.874763
> Avg: 51.982483 instant 55.835545
> Avg: 52.82121 instant 54.849483
> Avg: 49.67068 instant 57.75312
> Avg: 43.40379 instant 57.75312
>
> FXCanvas
> Avg: 0.0 instant 0.0
> Avg: 19.496336 instant 0.0
> Avg: 23.803656 instant 19.982939
> Avg: 25.214998 instant 27.849215
> Avg: 25.412786 instant 27.835789
> Avg: 25.731888 instant 26.75477
> Avg: 26.278933 instant 26.842173
> Avg: 23.945173 instant 28.574305
> Avg: 20.942469 instant 28.574305
>
> As you can see I got around 50% frame drop. But the problem is that the
> drop is really noticeable for the end user. I went to investigate the
> FXCanvas class, and saw something like this in it:
> // Consider optimizing this
> ImageData imageData = null;
> if ("win32".equals(SWT.getPlatform())) {
> PaletteData palette = new PaletteData(0xFF00, 0xFF0000,
> 0xFF000000);
> int scanline = width * 4;
> byte[] dstData = new byte[scanline * height];
> int[] srcData = buffer.array();
> int dp = 0, sp = 0;
> for (int y = 0; y < height; y++) {
> for (int x = 0; x < width; x++) {
> int p = srcData[sp++];
> dstData[dp++] = (byte) (p & 0xFF); //dst:blue
> dstData[dp++] = (byte)((p >> 8) & 0xFF); //dst:green
> dstData[dp++] = (byte)((p >> 16) & 0xFF); //dst:green
> dstData[dp++] = (byte)0x00; //alpha
> }
> }
> /*ImageData*/ imageData = new ImageData(width, height, 32,
> palette, 4, dstData);
> }
>
> Well, that looks bad. But even when I removed this looping - the
> performance gain was not that big. So the problem is somewhere else.
> My question is: is there any way to embed an JavaFX scene inside of an
> SWT application (E4) without such a performance drop? Will it get
> optimized in further JDK versions or it is unknown? Or maybe there are
> some optimization techniques that I can use for SWT to avoid this issues?
>
> Any advice would be great - because currently, the performance is quite
> a problem.
>
>
Re: Performance issue with FXCanvas [message #1388446 is a reply to message #1388305] Thu, 26 June 2014 13:08 Go to previous messageGo to next message
Michał Ćmil is currently offline Michał ĆmilFriend
Messages: 4
Registered: March 2014
Junior Member
Thanks for your reply.

Quote:
You better direct your questions towards Oracle - we do not maintain
that code! If I understand FXCanvas appropriately it renderes JavaFX
into an offscreen buffer and copies the pixels back and draws them on
the SWT-Canvas.


I've posted the question on the OTN forum. It looks like it is implemented as you've described it - the frames are rendered "twice". Additionally the color pallet update doesn't help (it is only done for windows, linux code doesn't do it).

Quote:

In the log run I think you are better of switching your e4 application
fully towards JavaFX, in case you have SWT-UI-Code our SWT on JavaFX
port might help you, it is able to render most buisness UIs.


I don't think it will be possible for us. We're using other components like ECP or NatTable. I'm afraid that they wont be working smoothly after switching to JavaFX Smile I guess we will have to try and optimize somehow our JavaFX drawing on the FXCanvas (or hope that it will be fixed in the future).

Re: Performance issue with FXCanvas [message #1388456 is a reply to message #1388446] Thu, 26 June 2014 13:23 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 26.06.14 15:09, Michał Ćmil wrote:
> Thanks for your reply.
>
> Quote:
>> You better direct your questions towards Oracle - we do not maintain
>> that code! If I understand FXCanvas appropriately it renderes JavaFX
>> into an offscreen buffer and copies the pixels back and draws them on
>> the SWT-Canvas.
>
>
> I've posted the question on the OTN forum. It looks like it is
> implemented as you've described it - the frames are rendered "twice".
> Additionally the color pallet update doesn't help (it is only done for
> windows, linux code doesn't do it).
> Quote:
>> In the log run I think you are better of switching your e4 application
>> fully towards JavaFX, in case you have SWT-UI-Code our SWT on JavaFX
>> port might help you, it is able to render most buisness UIs.
>
>
> I don't think it will be possible for us. We're using other components
> like ECP or NatTable. I'm afraid that they wont be working smoothly

There's a bottleneck in JavaFX Canvas which makes NatTable not working
on our SWT port - it renderers but extremly slow! This problem might get
fixed with jdk8u40.

ECP does not use that much of SWT so it should run without major
problems on SWTonJavaFX - the only problem might be the Forms-Toolkit
with is gradients, ... .

But if ECP internally would use its own subcomponent named EMF-Forms you
should be able to exchange the renderer and your form gets rendered with
pure JavaFX!

I would not bet Oracle fixing many things in FXCanvas, you better make
ECP run on pure JavaFX

Tom
Re: Performance issue with FXCanvas [message #1389222 is a reply to message #1388456] Fri, 27 June 2014 14:00 Go to previous message
Michał Ćmil is currently offline Michał ĆmilFriend
Messages: 4
Registered: March 2014
Junior Member
Thanks for the advice, we will be exploring our options in this area. I've submitted a bug for JavaFX at javafx-jira.kenai.com with code RT-37742, If anybody is interested in the progress of this issue.
Previous Topic:NIghtly build for win86-x64 does not work?
Next Topic:EList &lt;-&gt; ListProperty databinding
Goto Forum:
  


Current Time: Tue Apr 23 12:30:28 GMT 2024

Powered by FUDForum. Page generated in 0.04107 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top