-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Sodium.runIsolated
method to easily run computation heavy cryptographic operations in an isolate
#24
Comments
Generelly you are right, these calls are synchronous, as the dart API is simply a wrapper around the C API. However, for small payloads, these methods are quite fast and it should be OK to run them on the main isolate. When working with bigger files or the computation-heavy APIs (like pwhash), I would recommend you to indeed move the work to an isolate. However, this is out of scope for this library. You can easily use
|
Actually, I disagree that And in our case, I think we are pretty sure that encryption/decryption is a |
I do get your point, but there are a few problems with using isolates by default:
These are the most significant reasons why I currently do not want to change how the library is implemented. Especially with the new |
Thanks for explaining.
BTW I need to get a benchmark to see how long it take (with different length of values). I will send the reports here. |
Hi. Sorry for the late Reply. Regarding your points:
I think using the final result = sodium.runIsolated([secretKey1, secretKey2], (sodium, keys) {
final secretKey1 = keys[0];
final secretKey2 = keys[1];
return sodium.crypto.secretBox.easy(...);
}); Or even with a shortcut for a 1/2 keys final result = sodium.runIsolated1(secretKey, (sodium, secretKey) => sodium.crypto.secretBox.easy(...)); |
Okay, now I understand all details and trade-offs. |
That is true. However, I think I will spend some time seeing if this can be automated, as theoretically, the factories that create the sodium instances can be passed between isolates. So if the sodium instance "remembers" how it was created, this could be passed to the isolate. |
Sodium.runIsolated
method to easily run computation heavy cryptographic operations in an isolate
Speaking of using isolates, what's the right way to use libsodium inside of isolate? If I try to run: When you try to pass I've noticed that there is some way to pass the pointer down to the isolate: dart-lang/language#333 (comment) but I haven't tried it yet. |
The library will propably need a little adjustment (i.e. not calling For, now, until I have removed the void _isolateMain(RootIsolateToken rootIsolateToken) async {
BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);
final sodium = await SodiumPlatform.instance.loadSodium();
} |
@Skycoder42 Thanks for that, just tried and works flawlessly. |
|
Thanks! |
Hi. I want to ask a question.
Do we need to run sodium functions (such as
_sodium.crypto.genericHash.call()
or_sodium.crypto.secretBox.easy()
) behind an isolate? Because I am pretty sure that these jobs (hashing, encrypting, ...) take a long time (on a large amount of data) and might lead to frame drop.If the answer is yes, can we do that in the library (under the hood)? Because at the moment, functions are defined
sync
. We can make themasync
and return a Future to be able to run an isolate.The text was updated successfully, but these errors were encountered: