lyubo / react-native-sodium

ISC License
61 stars 46 forks source link

crypto_pwhash blocks the app on Android #36

Closed tasn closed 4 years ago

tasn commented 4 years ago

As you can see in https://reactnative.dev/docs/native-modules-android#threading slow operations should be dispatched to their own worker thread on Android. crypto_pwhash is the only slow enough operation for which it matters so it should be called in an internal thread.

lyubo commented 4 years ago

Did you try to update this package to the most recent version? I think there were some issues with libsodium@1.0.13.

tasn commented 4 years ago

I'm on 0.3.8.

Please reread my report. It's not related to libsodium, it's because it's a slow operation and it needs to run in a worker thread rather than the RN thread.

tasn commented 4 years ago

Just following up on this, it should be a very easy fix.

lyubo commented 4 years ago

@tsan: I've committed a version crypto_pwhash, which uses ExecutorService. You can test in your project. If it works OK we could publish a new build.

tasn commented 4 years ago

Great! What would you like me to test? Just a smoke test that it works?

Unfortunately though, as mentioned in https://github.com/lyubo/react-native-sodium/issues/35#issuecomment-701900738 I can't really update this library because of the bitcode incompatibility. :| Have you considered building the pre-compiled libs with an older xcode?

lyubo commented 4 years ago

Just test if it stops blocking your application's UI. I've checked it with the example app and it passed the test.

This change only affects Android. As for building with an older xcode, I'll check what version is on my home PC, as a can't downgrade my office's one.

tasn commented 4 years ago

Seem to be much better! There's still a small lag on my device, but I wonder if it's just because of the sudden load on the system, rather than the thread blocking.

I consider this one fixed. Thanks!