dormky 5 Posted Friday at 09:24 AM I'm drawing custom graphs, for now using GDI. Here's an example from a test project : It's a mess but that's because I'm testing as many possibilities as I can with the management of the axis. One problem that I'm running into is performance : 50ms to draw. This is annoying because it makes the graph jittery when dragging elements (lines and rectangles must be able to be moved by the user). I've made modifications so that it can be rendered by OpenGL, which is obviously MUCH faster (<8ms without looking very much at other performance improvements). Unfortunately initializing OpenGL takes multiple seconds. This is fine when you're running a game, but I have forms with 12 of these graphs on screen at the same time, all showing different stuff... So yeah. Is there any rendering engine on Windows that's got equivalent functionnality to GDI, but is just faster by vertue of using the GPU ? Any alternatives to consider ? Share this post Link to post
dormky 5 Posted Friday at 11:32 AM 9 minutes ago, Alexander Sviridenkov said: Use Direct2D I did, but performance wasn't that much better, only 50 % 😕 And that's discounting a bunch of issues I've had making it work (it's still not a one-to-one of what I get with GDI, while OpenGL is and didn't cause me implementation issues) Share this post Link to post
David Heffernan 2487 Posted Friday at 11:32 AM This can easily be drawn quickly with gdi. You don't need another library. 3 Share this post Link to post
Lars Fosdal 1930 Posted Friday at 01:00 PM @dormky Did you take a look at TeeChart? 1 Share this post Link to post
Cristian Peța 122 Posted Friday at 02:01 PM 4 hours ago, dormky said: One problem that I'm running into is performance : 50ms to draw Use a profiler and see what takes so much. I doubt that GDI drawing takes 50 ms for this on a modern CPU. Share this post Link to post
dormky 5 Posted Friday at 02:15 PM 2 hours ago, David Heffernan said: This can easily be drawn quickly with gdi. You don't need another library. Quickly yes, quickly enough no. And I'm already using things like Polyline and caching to reduce syscalls. Share this post Link to post
dormky 5 Posted Friday at 02:18 PM 1 hour ago, Lars Fosdal said: @dormky Did you take a look at TeeChart? Would TeeChart allow me to draw arbitrary shapes onto the graph ? From what I've this doesn't seem to be the case but I might have missed something. I need complete control over how the axis are laid out etc. Although if you know what exactly TeeChart uses under the hood that might point me in the right direction. 1 Share this post Link to post
dormky 5 Posted Friday at 02:19 PM (edited) 17 minutes ago, Cristian Peța said: Use a profiler and see what takes so much. I doubt that GDI drawing takes 50 ms for this on a modern CPU. Main bottleneck is the repeated calls to the gdi canvas to draw lines. I have code that prevents drawing unnecessarily (ie check if 2 points are far enough apart that they won't get resolved to the same coordinates) and this reduces the time proportionally to the size of the canvas used. Edited Friday at 02:20 PM by dormky Share this post Link to post
Javier Tarí 39 Posted Friday at 02:23 PM Did you tried with Skia and see what happens? Share this post Link to post
Cristian Peța 122 Posted Friday at 02:35 PM (edited) 23 minutes ago, dormky said: Main bottleneck is the repeated calls to the gdi canvas to draw lines. How many lines? GDI+ is slow but I suppose you are using GDI here. I have 174 ms for 46000 lines. EDIT: That means 13300 lines per 50 ms Edited Friday at 02:43 PM by Cristian Peța Share this post Link to post
Cristian Peța 122 Posted Friday at 02:41 PM 20 minutes ago, dormky said: Main bottleneck is the repeated calls to the gdi canvas to draw lines. If you profiled this then how much from that 50 ms take the calls to draw lines. Share this post Link to post
David Heffernan 2487 Posted Friday at 05:27 PM (edited) 3 hours ago, dormky said: Quickly yes, quickly enough no. And I'm already using things like Polyline and caching to reduce syscalls. Definitely quickly enough. So I use graphics 32 to draw off screen bitmap and blit that. Which is still gdi. But you aren't using gdi to draw lines to a DC. That's how you make it fast. It might even be fast enough to draw to off screen TBitmap and blit that. Edited Friday at 05:29 PM by David Heffernan Share this post Link to post
david berneda 66 Posted Friday at 07:18 PM 4 hours ago, dormky said: Would TeeChart allow me to draw arbitrary shapes onto the graph ? From what I've this doesn't seem to be the case but I might have missed something. I need complete control over how the axis are laid out etc. Although if you know what exactly TeeChart uses under the hood that might point me in the right direction. Yes you can use the Chart1.Canvas methods that wrap around a real canvas (gdi, gdi+, opengl, skia etc) to draw anything. Axis have many property settings to position and configure them (and extra TChartAxis can be created). The "TeeNew" folder demo here, has aprox 700 forms, each showing different features of many categories: https://github.com/Steema/TeeChart-VCL-FMX-Samples/tree/main/VCL Share this post Link to post
Anders Melander 2117 Posted Friday at 08:08 PM Here's the Graphics32 Thick Lines example; Using TCanvas.LineTo (which is basically just a GDI LineTo) a single line takes 4.8 microsecond. That's over 10,000 lines per 50mS. If we're comparing GDI vs Graphics32 1:1 then it's the 206,000 vs 6,000,000 values that should be compared since those are both for aliased 1-pixel lines. That's on my new system. On my old system (~15 years old) things are quite a bit slower but still over 2,000 lines per 50mS: Interestingly, GDI on my new system is almost 5 times faster than the old, while Graphics32 is only twice as fast. This is likely because Graphics32 is CPU-bound while GDI is GPU-bound. 29 minutes ago, david berneda said: gdi, gdi+, opengl, skia etc Those are all slower than Graphics32. Apart from that I would definitely use a chart libraries for something like this rather than roll my own, but that's just me. One thing that has prevented me from using TeeChart in the past (way back, to be honest) was that it didn't draw anti-aliased, which made the graphics look like something from the 80s - and although I do love 80s music, the graphics sucked back then 🙂. Does it do anti-aliasing these days? 10 hours ago, dormky said: One problem that I'm running into is performance : 50ms to draw. This is annoying because it makes the graph jittery when dragging elements What does you chart control/update logic look like? Are you doing something like this: procedure TFoo.OnMouseMove(...); begin UpdateValues; RepaintChart; end; or like this: procedure TFoo.OnMouseMove(...); begin UpdateValues; Chart.Invalidate; end; procedure TFoo.OnChartPaint(...); begin RepaintChart; end; or maybe: procedure TFoo.OnMouseMove(...); begin UpdateValues; Chart.Invalidate; Chart.Update; end; procedure TFoo.OnChartPaint(...); begin RepaintChart; end; Share this post Link to post
david berneda 66 Posted Friday at 08:34 PM 21 minutes ago, Anders Melander said: Does it do anti-aliasing these days? Yes from many years ago, using gdi+ or opengl (and now Skia) in vcl. Fmx has antialias by default. Antialias can be enabled/disabled at runtime at any time (to draw 1 pixel line widths for example). About opengl, with TeeChart GLCanvas the speed is much more greater, maybe 100x vs gdi or skia (if using a fast gpu) but all (or mostly) is done at the cpu. I've always wanted to develop a TeeCanvas derived class to wrap Graphics32, but never finished it. 1 Share this post Link to post
Anders Melander 2117 Posted Friday at 08:40 PM 3 minutes ago, david berneda said: I've always wanted to develop a TeeCanvas derived class to wrap Graphics32, but never finished it. If you PM me the source of your GDI implementation I'll see if I can easily derive a Graphics32 version from it. 1 Share this post Link to post
dormky 5 Posted 6 hours ago On 9/19/2025 at 4:23 PM, Javier Tarí said: Did you tried with Skia and see what happens? Yeah, I completely forgot about Skia. Seems like there's a Skia4Delphi community project, will give it a try some time this week hopefully. Thank you ! Share this post Link to post
dormky 5 Posted 6 hours ago On 9/19/2025 at 4:41 PM, Cristian Peța said: If you profiled this then how much from that 50 ms take the calls to draw lines. 80% is calling PolyDraw. PolyDraw gets me the best GDI performance, but there might be other ways to handle things in GDI ? Don't forget that I'm doing this on a full screen (1440x2560) and that it seems to scale linearly with display size. Share this post Link to post
David Heffernan 2487 Posted 5 hours ago 9 minutes ago, dormky said: 80% is calling PolyDraw. PolyDraw gets me the best GDI performance, but there might be other ways to handle things in GDI ? Don't forget that I'm doing this on a full screen (1440x2560) and that it seems to scale linearly with display size. Are you drawing directly to screen DC? Or are you drawing to offscreen bitmap and blitting it? Because what you appear to be drawing is so trivial that I can't see any need at all for things like DirectX, OpenGL, Skia, etc. Not that these aren't all powerful tools. Just that you don't need them. It's not at all clear to me that you've actually diagnosed the problem yet. 2 Share this post Link to post
dormky 5 Posted 3 hours ago 2 hours ago, David Heffernan said: Are you drawing directly to screen DC? Or are you drawing to offscreen bitmap and blitting it? Because what you appear to be drawing is so trivial that I can't see any need at all for things like DirectX, OpenGL, Skia, etc. Not that these aren't all powerful tools. Just that you don't need them. It's not at all clear to me that you've actually diagnosed the problem yet. I'm drawing to a TBitmap as a buffer, and then using Canvas.Draw(). Share this post Link to post
david berneda 66 Posted 2 hours ago On 9/19/2025 at 4:15 PM, dormky said: Quickly yes, quickly enough no. And I'm already using things like Polyline and caching to reduce syscalls. Maybe you can draw non-repeated points? There are some algorithms to average min max at every X, and dont paint repeated data. TeeChart does not use Polyline. https://github.com/Steema/TeeChart-VCL-FMX-Samples/blob/ffa84bce472cd3ec17fab60c53c178da9e4047e6/VCL/TeeNew/FastLine_DrawAll.pas#L54 Share this post Link to post
Renate Schaaf 78 Posted 2 hours ago You might be doing unnecessary updates to screen, that's what makes these drawings slow in my experience. On my system LineTo is faster than polyline. Share this post Link to post
dormky 5 Posted 2 hours ago 12 minutes ago, david berneda said: Maybe you can draw non-repeated points? There are some algorithms to average min max at every X, and dont paint repeated data. TeeChart does not use Polyline. https://github.com/Steema/TeeChart-VCL-FMX-Samples/blob/ffa84bce472cd3ec17fab60c53c178da9e4047e6/VCL/TeeNew/FastLine_DrawAll.pas#L54 I need to be able to draw data points as both a continuous line and separate points ; I do remove points that aren't far enough from the previous point to produce a change (I simply check that the difference is superior to half of what a pixel is worth). If I don't do that I'm looking at like 200ms easily lol. For reference, my test data is a 12k points sine wave. I also keep a buffer of the whole background, axis etc. to not redraw them everytime. It's just the data. Share this post Link to post
dormky 5 Posted 2 hours ago 15 minutes ago, Renate Schaaf said: You might be doing unnecessary updates to screen, that's what makes these drawings slow in my experience. On my system LineTo is faster than polyline. Jesus I just tested for benchmarking's sake and not using Polydraw is easily a x5 improvement 😭 What the hell Share this post Link to post