You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Implement a GET method that returns its response payload as bytes.
Use Uint8List.fromList(payloadAsListOfInt) to convert the Retrofit response data to a Uint8List.
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.
Describe the bug
When getting a response payload as bytes, we hit performance issues due to the conversion from
List<int>
toUint8List
.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 supportUint8List
as a response type. Instead, we must useList<int>
along withResponseType.bytes
. Converting fromList<int>
toUint8List
works, but it's very costly and most importantly wasteful, because the underlying Dio response supportsUint8List
.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:
Uint8List.fromList(payloadAsListOfInt)
to convert the Retrofit response data to aUint8List
.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 usingResponseType.bytes
to efficiently access the raw payload bytes.Additional context
The text was updated successfully, but these errors were encountered: