4 Replies Latest reply on Mar 9, 2011 9:21 AM by Sebastian Zarzycki

    SHA256 calculation very slow

    Sebastian Zarzycki Level 1

      I'm trying to calculate a "digital fingerprint" of a file. The fingerprint should be a SHA256 hash. Sadly, current runtime (AIR 2.5.1 + Flex 4.1) is horribly struggling with this. There are three choices :

       

      - SHA256 straight from framework (mx.utils)

      - SHA256 from as3corelib

      - SHA256 from as3crypto

       

      The first one processes 5mb file in 2.5s

      The second - 8s.

      The last one - 20s.

       

      These are data from "release build" versions.

       

      How is it possible that it takes 2.5s for AIR to calculate something that natively (or even in PHP) takes 15-20 miliseconds? Is there any way I can speed this up? I've tried to use Apparat, but the normal action doesn't change anything. Injecting Memory access for Alchemy opcodes seems like a big task (not that easy to rewrite an algorithm that uses readBytes instead of readByte).

       

      Any help?

        • 1. Re: SHA256 calculation very slow
          Flex harUI Adobe Employee

          Actionscript doesn't execute at native speeds.

           

          One option is to call a native process.

          • 2. Re: SHA256 calculation very slow
            Sebastian Zarzycki Level 1

            Right... I'm using AIR just to call native process to calculate SHA... doesn't make any sense and I lose cross-platform. I know actionscript does not execute as quick as native. The question is, why is the difference so huge and if there's anything I can do to speed it up. The implementation made by Adobe seems to be fairly optimized, no function calls, everything inline, bitwise operations. Yet, it's still way to slow for this kind of usage. I understand someone might say "well don't use flex then". but the point is to actually use it.

            • 3. Re: SHA256 calculation very slow
              Flex harUI Adobe Employee

              There is very little optimization of the instructions in the Actionscript

              compilers and runtime.  There may be some layers around file i/o as well for

              platform isolation and security.  The dynamic nature of the language

              sometimes gets in the way of optimizations.

               

              There's a whole team of folks trying to make Actionscript execute faster.

              Right now, you have to make some tradeoffs of cross-platform vs performance.

              • 4. Re: SHA256 calculation very slow
                Sebastian Zarzycki Level 1

                As I said, I don't mind the tradeoff, I am however concerned with how inferior the performance actually is compared to native speeds.

                 

                For reference, what I did in the end was compiling some part of openssl into alchemy code. That yielded good results.