Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are ints always faster than Numbers/Floats in AS3?

Flash is known to behave in very unpredictable ways ways when it comes to manipulating data. I'm curious that if there is any performance/memory benefit to using Numbers instead of ints aside from values that need precision. I have heard that some basic operations in Flash may convert multiple times between the two type to resolve the expression. I've also heard that Flash runtime, under the hood, actually maps ints to non-precision Numbers/Floats during runtime. Is any of this true?

like image 228
Jonathan Dunlap Avatar asked Mar 01 '12 22:03

Jonathan Dunlap


1 Answers

Flash runtime is a dark place indeed.

  • As you mentioned AVM2 does convert big ints into Number.
  • Whole Numbers are actualy ints.
  • And there's more stuff about ints.
  • Uints used to be slow used in a loop BUT NOW THEY ARE NOT (results in the article seem to be a combination of weird bytecode generation and JIT optimizations).
  • Numbers take more space in memory but this is nothing compared to even a single JPEG file.
  • Logically it feels better to use uints in loops.
  • Numbers are floating point falues you have to be careful comparing them.

Jackson Dunstan does pretty good tests of different AS3 language constructs performance. Of course it's always good to check results yourself. From the series about 10.2 performance you can see that with every new Flash Player version they optimize something but other things might get slower: 1 2 3.

P.S. This answer might get old very soon and might as well be cited in a couple of years later which of course will be wrong.

like image 154
Valentin Simonov Avatar answered Sep 29 '22 12:09

Valentin Simonov