Very slow TCanvas::Print on png file for big graphs when in batch mode

I have to produce png files for various canvases containing graphs with a large number of points. When I do this in batch mode it takes a very long time, while if I do it in interactive mode it is much much faster. I attach a very simple script which I put together to reproduce the issue. These are the outcomes when launching it in the two different modes:

Both cases produce the same output png file. Am I doing something wrong or is this the expected behaviour? I’d really need to be able to produce the pngs in batch mode but with these wall times it is impossible, so any help will be appreciated. Thanks.
test.C (230 Bytes)

In interactive mode the picture is produced on screen quickly by a fast graphics system (X11, Quartz, etc …) then dumped on png as a bitmap. In batch the the liberafterimage library is used via TASImage to draw the picture… and it is much slower…

Thank you, I imagined something like this. Is there any workaround for this? Something dirty like drawing on a fake window or screen buffer which is not displayed nor requires an actual screen and then dumping on png?

I remember there are ways to hide the X11 windows … but I forgot what it was…
that’s external to ROOT anyway…

I tried several hacks, like dumping the canvas on a SVG (which is very fast because SVG is vector, I think) and then convert the SVG to a PNG before assembling all the PNGs into a PDF. The bottleneck here is the SVG-PNG conversion, which takes up to several minutes for each canvas, depending on the conversion library (I tried ImageMagick, svg2png etc.), which more or less matches what can be obtained by using libafterimage via TASImage to dump the canvas directly on a PNG.
I wonder how X11 can be so much faster in rendering the graphical entities than any other rendering library: on my pc a canvas with its full content is displayed within a second, how can libafterimage & co. be so much slower? Is there a way to replicate this X11 magic outside X11?

I’ve found a very dirty workaround that saves the day. To let Root draw the canvases via X11 (and then quickly dump them into PNGs which are then assembled into a PDF via ImageMagick/Magick++) in a headless batch system I used Xvfb, an X server with a virtual framebuffer. With an Xvfb display available, my Root application believes to be running in a fully interactive session even on a machine with no physical screen, thus it actually renders the canvases via X11 etc.

Ah yes right … that’s it : Xvfb