Closed aytunch closed 4 years ago
My approach to this problem is base on economics ... Expensive low level operations are better handled by optimised langs like go, rust or C. On the long run it's much more cheap.
If would advise to run FAAS using https://github.com/woltapp/blurhash/tree/master/C
Having a dart encoder on the server side has few advantages and the case of encoding should not be handled by the client.
Thanks for sharing your idea.
@Solido thanks for your reply, it makes sense. For my last part of the question regarding cloud functions which I am not experienced with, do you have any idea if it is possible to encode the images calling the C library you provided above? Do you have plans on working with the Firestore Cloud Functions part of this great package?
@Solido I agree that most of the time you would want to do this server side but there are cases like ours where it makes a lot of sense to generate the hash on a Flutter based desktop client. Computing power is not the problem there but we could optimize further by wrapping the C library. Would you accept a PR doing the encoding?
@aytunch I am currently using a cloud function to generate the hash using the Python package which also wraps the C library.
@cbenhagen Ben, thanks a lot for these. Just to make sure, is this the way to upload your Python package to Cloud Functions?
Yes that should get you started. Be sure to checkout the links at the bottom of that document to see more in depth guides on cloud functions.
Inside of the BlurHash Algorithm details they have an example of Swift Decoder and Swift Encoder. I believe Swift is not a backend language. Maybe this can help porting the encoder code to dart from swift.
@cbenhagen I see the kind of solutions your working on and for some reasons it appears that desktop encoding is the way to go.
We have 3 solutions
Do you think the last two have any advantages compared to resizing assets and sampling with dart ?
I'd highly prefer a pure Dart solution which uses whatever Flutter provides for resizing. Not sure if the slight speed increase a native solution might bring would justify the burden of maintaining it for all the platforms.
Let's go for a pure dart implementation yet I'll keep an eye on FFI/Rust later on.
@Solido @cbenhagen I just found out about this package which seems to do the encoding part in Dart. It does not have a nice Widget wrapper though.
First of all thank you for introducing us Flutter community with this great tool. It is a game changer. For this to reach to broader developers I think we should be able to encode the image to it's corresponding blurhash string. Are you planning on writing a function which does this on the client. This way we can upload the image along with the blurhash to Firestore and Firebase Storage at the same time. People might not be using server side code(cloud functions) since they will bring extra pricing/delay/performance issues. If this is not a good way, then I hope someone would show an cloud function example in type script.