views:

31

answers:

2

I was trying to get a ballpark idea of how much slower Flash is at pure pixel-pushing 2D graphics than doing the same thing in SDL or other native library. For instance if I have a Flash/Flex app on a modern PC which each frame does a 2D loop and directly reads/sets every pixel, what equivalent PC would give the same performance for a native C++ app? Maybe a classic Pentium, a PII, PIII? I know it's probably not quite a linear relationship but it must be possible to get some kind of idea.

+4  A: 

Recent Flash versions talk directly to the video driver, so the difference is a lot less than you'd think.

Ignacio Vazquez-Abrams
I didn't say how much I think, how do you know it's a lot less? :) Also, direct video driver communication doesn't remove the issue AS3 is inherently slow since it's still IIRC interpreted rather than using JIT (is that true?)
John
No, Tamarin has a JITer.
Ignacio Vazquez-Abrams
Thanks for that. From their site "The Tamarin virtual machine is used within the Adobe® Flash® Player and is also being adopted for use by projects outside Adobe." Does that mean it's part of standard Flash, or is Firefox-only? Regardless, can you clarify "less than you'd think"
John
It's still in use in Flash; and Firefox is actually still using SpiderMonkey. The speed difference is closer to 10% than 10×.
Ignacio Vazquez-Abrams
Can anyone provide any links/references on this?
John
+2  A: 

It would be very, very slow for a generic 2d rewrite using getPixel()/setPixel() on every frame. You basically can't push pixels and expect real time performance.

However, it always depends on what you're trying to do. Many of the most common animation techniques can instead be done by using native (player-accelerated) features and that's faster in Flash. For example, if you wanted a rectangle moving around the screen, you wouldn't push it on a BitmapData instance, you could just have a native box moving; if you want to transform a video to blur it, you could use the native BlurFilter filter; if you want to change overall color of an image, you can use a color matrix instead; if you want to apply some 3d transformation to something, you can use the native 3d transformers; and so on and so forth.

For serious, lower-level pixel pushing, you can also use Pixel Bender, Flash's pixel shader language. It can do much faster pixel pushing (C-level speeds) but it's limited. It works great if you want to, say, build your own filters/shaders or blending modes, but it's not for SDL-level stuff. People have created proof-of-concept demos like low-res raycasting demos, but that's about the top of what you can do.

If you want real C performance and you're thinking of SDL or something similar, you may be better off by actually doing your stuff in C and using Alchemy to compile. There's a port of SDL to Flash, for example, or even complete ports of id Software's DOOM/Hexen/Heretic - all using native code, with some tweaks for UI.

zeh