dart_algolia
dart_algolia copied to clipboard
Decoding JSON in an Isolate
Hi,
Since the JSON payloads can be quite large, using json.decode()
on the main thread could cause janking.
One solution would be to expose a method that does the decoding which defaults to json.decode
but allow it to be overridden in order to use compute()
or any other Isolate
method.
Internally, all references in the package to json.decode(response.body)
would have to be replaced with something like await algolia.decodeJson(response.body)
,
Example:
class Algolia {
// ... stuff
/// The method that one can override
FutureOr<dynamic> decodeJson(String payload) => json.decode(payload);
}
This can then be overridden by the user using compute()
, for example
class MyAlgolia extends Algolia {
// ... stuff
@override
FutureOr<dynamic> decodeJson(String payload) => compute(json.decode, payload);
}
If you're happy with this approach, I can write up something and submit a PR.