diff --git a/links/gql_http_link/CHANGELOG.md b/links/gql_http_link/CHANGELOG.md index 91bb7a17..e8c262cd 100644 --- a/links/gql_http_link/CHANGELOG.md +++ b/links/gql_http_link/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.0 + +- improve JSON decoding performance by taking advantage + Darts hidden _JsonUtf8Decoder obtained by fusing `Utf8Decoder` and `JsonDecoder` + ## 1.0.1+1 - add topics diff --git a/links/gql_http_link/lib/src/link.dart b/links/gql_http_link/lib/src/link.dart index 757bd582..566689b7 100644 --- a/links/gql_http_link/lib/src/link.dart +++ b/links/gql_http_link/lib/src/link.dart @@ -39,17 +39,23 @@ class HttpLink extends Link { /// the decoded map will be then passes to the `RequestSerializer`. /// It is recommended for performance to decode the response using `compute` function. /// ``` - /// httpResponseDecoder : (http.Response httpResponse) async => await compute(jsonDecode, httpResponse.body) as Map, + /// httpResponseDecoder : (http.Response httpResponse) => Isolate.run(() => + /// const Utf8Decoder() + /// .fuse(const JsonDecoder()) + /// .convert(response.bodyBytes) as Map?)) /// ``` HttpResponseDecoder httpResponseDecoder; - static Map? _defaultHttpResponseDecoder( + // use the hidden _JsonUtf8Decoder obtained by fusing + // Utf8Decoder and JsonDecoder + // see https://github.com/dart-lang/sdk/blob/5b2ea0c7a227d91c691d2ff8cbbeb5f7f86afdb9/sdk/lib/_internal/vm/lib/convert_patch.dart#L40 + static final Converter _defaultHttpResponseDecoder = + const Utf8Decoder().fuse(const JsonDecoder()); + + static Map? _defaultHttpResponseDecode( http.Response httpResponse) => - json.decode( - utf8.decode( - httpResponse.bodyBytes, - ), - ) as Map?; + _defaultHttpResponseDecoder.convert(httpResponse.bodyBytes) + as Map?; http.Client? _httpClient; @@ -65,7 +71,7 @@ class HttpLink extends Link { http.Client? httpClient, this.serializer = const RequestSerializer(), this.parser = const ResponseParser(), - this.httpResponseDecoder = _defaultHttpResponseDecoder, + this.httpResponseDecoder = _defaultHttpResponseDecode, this.followRedirects = false, }) : uri = Uri.parse(uri) { _httpClient = httpClient ?? http.Client(); diff --git a/links/gql_http_link/pubspec.yaml b/links/gql_http_link/pubspec.yaml index 1ed60341..b8862b35 100644 --- a/links/gql_http_link/pubspec.yaml +++ b/links/gql_http_link/pubspec.yaml @@ -1,9 +1,9 @@ name: gql_http_link -version: 1.0.1+1 +version: 1.1.0 description: GQL Terminating Link to execute requests via HTTP using JSON. repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.13.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: gql: ^1.0.0 gql_exec: ^1.0.0