From jp at jamesparker.me Wed Apr 6 21:25:37 2016 From: jp at jamesparker.me (James Parker) Date: Wed, 6 Apr 2016 17:25:37 -0400 Subject: [Haskell-iPhone] FFI calls into Haskell taking a long time Message-ID: Hi, I?m exporting a Haskell function that generates RSA keys for an iOS application. I?m using the crypto-pubkey and crypto-random packages. Unfortunately, the key generation is taking an extremely long time (around 5 minutes) when run in the simulator (XCode 7.2.1). When running Haskell code through Criterion, key generation only takes 110ms. When benchmarking a c program that links the Haskell FFI library (on my x86 laptop), key generation takes about 130ms. Does anyone have any ideas why this is so much slower on the simulator? I thought maybe there was an issue with running out of randomness, so I tried creating a fixed seed by using `createTestEntropyPool`, but this did not make any difference. I?ve included the relevant key generate function below. gen :: MonadRandom m => m (RSA.PublicKey, RSA.PrivateKey) gen = withCPRG $ \prg -> return $ RSA.generate prg 256 65537 instance MonadRandom IO where type MonadCPRG IO = SystemRNG withCPRG f = do entropy <- createEntropyPool (res, _) <- f $ cprgCreate entropy return res I?d appreciate any help. Thanks! James From chak at justtesting.org Wed Apr 6 23:45:25 2016 From: chak at justtesting.org (Manuel M T Chakravarty) Date: Thu, 7 Apr 2016 09:45:25 +1000 Subject: [Haskell-iPhone] FFI calls into Haskell taking a long time In-Reply-To: References: Message-ID: Did you try on the device? The simulator is a strange beast and its performance may not be representative of what you get on a real device. Manuel > James Parker : > > Hi, > > I?m exporting a Haskell function that generates RSA keys for an iOS application. I?m using the crypto-pubkey and crypto-random packages. Unfortunately, the key generation is taking an extremely long time (around 5 minutes) when run in the simulator (XCode 7.2.1). When running Haskell code through Criterion, key generation only takes 110ms. When benchmarking a c program that links the Haskell FFI library (on my x86 laptop), key generation takes about 130ms. > > Does anyone have any ideas why this is so much slower on the simulator? I thought maybe there was an issue with running out of randomness, so I tried creating a fixed seed by using `createTestEntropyPool`, but this did not make any difference. I?ve included the relevant key generate function below. > > gen :: MonadRandom m => m (RSA.PublicKey, RSA.PrivateKey) > gen = withCPRG $ \prg -> return $ RSA.generate prg 256 65537 > > instance MonadRandom IO where > type MonadCPRG IO = SystemRNG > > withCPRG f = do > entropy <- createEntropyPool > (res, _) <- f $ cprgCreate entropy > return res > > I?d appreciate any help. > > Thanks! > > James > _______________________________________________ > iPhone mailing list > iPhone at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/iphone From shabazakhan at gmail.com Fri Apr 8 11:51:13 2016 From: shabazakhan at gmail.com (Shahbaz Khan) Date: Fri, 8 Apr 2016 07:51:13 -0400 Subject: [Haskell-iPhone] (no subject) Message-ID: <006901d1918c$f3d55b30$db801190$@gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: From jp at jamesparker.me Fri Apr 8 18:47:10 2016 From: jp at jamesparker.me (James Parker) Date: Fri, 8 Apr 2016 14:47:10 -0400 Subject: [Haskell-iPhone] FFI calls into Haskell taking a long time In-Reply-To: References: Message-ID: <1893514E-DCE0-40F9-9FFA-F255AC2FDB26@jamesparker.me> Hi, Sorry, it took a while to get running on the device. Yes, I still get the slowdown on the device. XCode is reporting 99-100% CPU usage while memory stays pretty consistent (around 18MB). This is similar to what I was seeing on the simulator. Are there any tools to benchmark where time is being spent on the device? Is there some way to enable -enable-library-profiling? Thanks, James > On Apr 6, 2016, at 7:45 PM, Manuel M T Chakravarty wrote: > > Did you try on the device? The simulator is a strange beast and its performance may not be representative of what you get on a real device. > > Manuel > >> James Parker : >> >> Hi, >> >> I?m exporting a Haskell function that generates RSA keys for an iOS application. I?m using the crypto-pubkey and crypto-random packages. Unfortunately, the key generation is taking an extremely long time (around 5 minutes) when run in the simulator (XCode 7.2.1). When running Haskell code through Criterion, key generation only takes 110ms. When benchmarking a c program that links the Haskell FFI library (on my x86 laptop), key generation takes about 130ms. >> >> Does anyone have any ideas why this is so much slower on the simulator? I thought maybe there was an issue with running out of randomness, so I tried creating a fixed seed by using `createTestEntropyPool`, but this did not make any difference. I?ve included the relevant key generate function below. >> >> gen :: MonadRandom m => m (RSA.PublicKey, RSA.PrivateKey) >> gen = withCPRG $ \prg -> return $ RSA.generate prg 256 65537 >> >> instance MonadRandom IO where >> type MonadCPRG IO = SystemRNG >> >> withCPRG f = do >> entropy <- createEntropyPool >> (res, _) <- f $ cprgCreate entropy >> return res >> >> I?d appreciate any help. >> >> Thanks! >> >> James >> _______________________________________________ >> iPhone mailing list >> iPhone at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/iphone > From jp at jamesparker.me Fri Apr 15 21:10:16 2016 From: jp at jamesparker.me (James Parker) Date: Fri, 15 Apr 2016 17:10:16 -0400 Subject: [Haskell-iPhone] FFI calls into Haskell taking a long time In-Reply-To: <1893514E-DCE0-40F9-9FFA-F255AC2FDB26@jamesparker.me> References: <1893514E-DCE0-40F9-9FFA-F255AC2FDB26@jamesparker.me> Message-ID: <0C194B48-5CA4-4EC1-89EB-FFF4F08DFAEB@jamesparker.me> Hi, I?ve been looking into this some more. It looks like generatePrime is causing the slowdown. I manually added some benchmarking and logging to this function and its dependencies (I removed the gmp code). Here is the output from the iOS version: http://lpaste.net/6160729019554725888 Here is the output run natively on my machine: http://lpaste.net/2971101072195584000 As you can see, the iOS version is much slower (about 75x). What differences are there when cross-compiling for iOS that might explain this difference? It looks like the iOS version might be using integer-simple instead of gmp? Are there any other differences? Thanks! James > On Apr 8, 2016, at 2:47 PM, James Parker wrote: > > Hi, > > Sorry, it took a while to get running on the device. Yes, I still get the slowdown on the device. XCode is reporting 99-100% CPU usage while memory stays pretty consistent (around 18MB). This is similar to what I was seeing on the simulator. > > Are there any tools to benchmark where time is being spent on the device? Is there some way to enable -enable-library-profiling? > > Thanks, > > James > >> On Apr 6, 2016, at 7:45 PM, Manuel M T Chakravarty wrote: >> >> Did you try on the device? The simulator is a strange beast and its performance may not be representative of what you get on a real device. >> >> Manuel >> >>> James Parker : >>> >>> Hi, >>> >>> I?m exporting a Haskell function that generates RSA keys for an iOS application. I?m using the crypto-pubkey and crypto-random packages. Unfortunately, the key generation is taking an extremely long time (around 5 minutes) when run in the simulator (XCode 7.2.1). When running Haskell code through Criterion, key generation only takes 110ms. When benchmarking a c program that links the Haskell FFI library (on my x86 laptop), key generation takes about 130ms. >>> >>> Does anyone have any ideas why this is so much slower on the simulator? I thought maybe there was an issue with running out of randomness, so I tried creating a fixed seed by using `createTestEntropyPool`, but this did not make any difference. I?ve included the relevant key generate function below. >>> >>> gen :: MonadRandom m => m (RSA.PublicKey, RSA.PrivateKey) >>> gen = withCPRG $ \prg -> return $ RSA.generate prg 256 65537 >>> >>> instance MonadRandom IO where >>> type MonadCPRG IO = SystemRNG >>> >>> withCPRG f = do >>> entropy <- createEntropyPool >>> (res, _) <- f $ cprgCreate entropy >>> return res >>> >>> I?d appreciate any help. >>> >>> Thanks! >>> >>> James >>> _______________________________________________ >>> iPhone mailing list >>> iPhone at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/iphone >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: