Skip to content
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

Poor performance when retrieving payload as bytes #724

Open
jeanplevesque opened this issue Nov 13, 2024 · 0 comments
Open

Poor performance when retrieving payload as bytes #724

jeanplevesque opened this issue Nov 13, 2024 · 0 comments

Comments

@jeanplevesque
Copy link

Describe the bug
When getting a response payload as bytes, we hit performance issues due to the conversion from List<int> to Uint8List.

In our use-case, we download binary files and we simply want the raw response as a Uint8List byte buffer to then read it later on. This brings an interesting problem where Retrofit doesn't directly support Uint8List as a response type. Instead, we must use List<int> along with ResponseType.bytes. Converting from List<int> to Uint8List works, but it's very costly and most importantly wasteful, because the underlying Dio response supports Uint8List.

In our specific situation, we actually removed Retrofit from this endpoint implementation and instead directly use Dio to avoid this cycle of conversions.
Uint8List -> List<int> -> Uint8List

To Reproduce
Steps to reproduce the behavior:

  1. Implement a GET method that returns its response payload as bytes.
    @GET('/data')
    @DioResponseType(ResponseType.bytes)
    Future<HttpResponse<List<int>?>> getData();
  2. Use Uint8List.fromList(payloadAsListOfInt) to convert the Retrofit response data to a Uint8List.
  3. Notice that the Uint8List.fromList takes a lot of time, especially with large payloads.
    In our case, this took ~800ms for a response payload of about 9MB.

Expected behavior
Retrofit should support Uint8List as a response type when using ResponseType.bytes to efficiently access the raw payload bytes.

Additional context

environment:
  sdk: '>=3.4.0 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  retrofit: ^4.0.3
  retrofit_generator: ^8.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant