General code speed Xojo 64 bit vs RealStudio 32 bit

How are you creating the image to draw into?

Nothing to offer on the technical aspect but I did see that airship floating over San Francisco long ago…

An ordinary New Picture once at the opening of the program, which is then reused continuously. It’s only really changes when the canvas is resized.

OK, technically, it’s actually two images, a base image, and a second image containing stuff not being changed since the last update. An update starts by drawing the storage image, followed by drawing the dynamic stuff, and where the program automatically skips the non-dynamic parts. Makes the hole update run faster.

Yes, the airship was used for promoting the releases of the movie Despicable Me two movie and toured all over the US during some time before the release of the movie. These movie companies seem to have too much money to spend on PR, but on the other hand it probably generated a lot of free PR for the movie. I have done done eight or nine such image wraps in the past on airships, though the example is the biggest so far. Here is a link to a short movie showing how the wrap was done if anybody is intested. http://www.touchcad.se/Despicablimp.mov

2 Likes

IIRC you’re using a Retina Mac? If so, this explains the “performance” increase you’re getting. As I would hazard a guess to say that the images are not @2x, only @1x ( 1/4 of the pixels ).

Switching to window.bitmapForCaching will give you an image that matches the display resolution.

Tried it both on a Retina and non retina Mac. The difference remains though it’s smaller on the Retina machines for some reason. I have tried every possible combination, but drawing lines especially is slower by a factor of 4 to 7 times. This is of course a big problem in this case, as the sailboat mesh alone contains about 48000 lines, which in the world of this program is not even an average sized model.

Couple of ideas:

  1. If you are drawing individual lines have you tried the GraphicsPath class to combine multiple draw commands as it might avoid some setup / teardown overhead.

  2. If you have the MBS plugins have you tried using the CGContextMBS commands instead of the Xojo ones?

Yes, I tried the GraphicsPath but it was slower than using lines. Was a little surprised about that, as a polygon based on lines basically uses twice as many coordinates. But no luck there. It seems as if the overhead grinding takes very little time compared to the actual drawing.

I wrote a small test rig to test some of the drawing elements, and compare whether drawing directly or on a picture. When it comes to drawing in a picture vs directly, the picture method used to be much faster. Now, the results where much more even and inconclusive, though the picture method was faster on lines, but not by much. Dry running the rig, that is, doing everything except actually drawing showed that drawing used 98% of the time.

I have now basically tried everything I could think of to extract more speed, so I guess it’s now time to see if there are any other options, like the CGContextMBS commands. Thanks for the suggestions !

I have now basically tried everything I could think of to extract more speed,<

Just chucking this out there, but have you tried turning off anti-aliasing?
Im guessing that trying to add little grey blobs along the line to make it smooth must add to the processing time when drawing lines.

The first thing you could try is using the Xojo drawing command but switching off anti-aliasing on the graphics context.

(note. g is the Xojo Graphics object)

Dim cgContextObj As CGContextMBS

cgContextObj  = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef))

cgContextObj.SetAllowsAntialiasing(False)
cgContextObj.SetShouldAntialias(False)

... draw into g

Anti Aliasing has been off for a very long time now. It does slow things down a lot

I have done some testing using the CGContexMSB thing. I generated a simple test rig generating 48000 lines divided into 240 “polygon” style shapes. Here are the results:

Polygons drawn directly on a canvas Xojo 1.417 Seconds
Polygons drawn on a picture, paint into a Canvas Xojo 1.367 Seconds
Lines drawn directly on a canvas Xojo 0.663 Seconds
Lines drawn on a picture, paint into a Canvas Xojo 0.367 Seconds
Lines drawn on a picture, paint into a Canvas MSB 0.200 Seconds
Polygons drawn on a picture, paint into a Canvas MSB 0.067 Seconds

Quite a gap it seems. What I haven’t yet been able to figure out is how to make practical use of the MSB thing. For some reason, it does not allow me to draw in my picture, which I really need. The drawing structure is highly complex and flexible so contributions to the final display image comes from many sources. Ah well, perhaps I can figure it out.

Here is the massively unimpressive test shape.

1 Like

I suspect the problem may be that Xojo 's draw commands do more than just DrawLine but maybe also are restoring things on the Context and do such in every single call.

(am speculating this from some things have worked in the past)

If that is true then you could possibly speed it by getting the context and then drawing with declare.

2 Likes

Please use CGBitmapContextMBS class to draw with CGContextMBS into a Xojo picture.

see this method:

You might be able to use: CGBitmapContextMBS.CreateWithPicture and draw into that.

I suggest you also log a feedback case with your findings as it might be something they can improve.

Thank you @kevin_g for also pointing to my plugin class.

Who did flag my posting?
@Claes_Lundstrom explicitly asked how to use the plugin!

Might be wanting to plan optimizing code for the ARM GPU/CPUs…and not for Intel anymore since Mac will drop Intel.
Or maybe even on the most recent AMD CPU/GPU you’d get much faster results.

" Please use CGBitmapContextMBS class to draw with CGContextMBS into a Xojo picture.
see this method:

Hm. It seems as it’s Mac OS only. I generally prefer using the same code on both Mac and Windows whenever possible.

That won’t fly. The underlaying APIs are very different. Xojo hides that a bit for you.

For Windows, I started adding things via DirectDrawGraphicsMBS class.

Thanks for the update on your classes