cancel
Showing results for 
Search instead for 
Did you mean: 

BTP Android SDK: copying a the byte stream retrieved from /$value request is very slow

robertgerling
Explorer
0 Kudos

Hi Community,

were are currently migrating various native Android Apps from SMP to BTP.

Some offline entities are used to transfer image data and we noticed a tremendous performance decrease when copying the byte stream using the BTP SDK (4.0.1).

We configure the OfflineODataDefiningQuery for the respective entities with automaticallyRetrieveStreams flag in the constructor to be true. When the initial open() request of the ODataOfflineProvider completes successfully we query the byte streams of the entities by using the /$value syntax and copy the stream to the file system, for better handling of the images during various use cases within our apps.

The code basically looks something like this.

// retrieve the stream from the ODataOfflineProvider
final DataQuery request = new DataQuery();
request.setRequestPath(resourcePath); //the resource path ends with /$value
final HttpHeaders headers = new HttpHeaders();
final RequestOptions options = new RequestOptions();
final QueryResult response = oDataOfflineProvider.executeQuery(request, headers, options);
if (response.getError() != null) {
    throw new DatabaseException(response.getError());
} else {
    // Copy the image data from the retrieved byte stream
    InputStream src = ByteStream.toInput(response.getByteStream())
    byte[] buf = new byte[1024];
    int len;
    try {
        while((len = src.read(buf)) > 0) {
            dst.write(buf, 0, len);
        }
    } finally {
        src.close();
        dst.close();
    }
} 

In comparison to the SMP SDK we get a really significant performance decrease:<img data-attachment="2033894" src="/storage/temp/2033894-performance-comparsion-smp-btp.png" alt="performance-comparsion-smp-btp.png" style="background-color: initial; font-family: Arial, Helvetica, Verdana, Tahoma, sans-serif; font-size: 15px; white-space: normal; color: inherit;">
The code that copies the streams as well as the other external parameters (threading model, device the code runs on, ...) has not changed.<br>

Does anybody have an idea what's going on here or how we gone fix it?

Kind regards,

Robert

Accepted Solutions (0)

Answers (1)

Answers (1)

evanireland
Advisor
Advisor

I suppose you could open a "performance bug" to request for the InputStream returned by ByteStream.toInput performance to be improved.

But something that may perform better right now would be:

response.getByteStream().copyToFile(fileName)
robertgerling
Explorer
0 Kudos

Hey Evan,

thank you very much for your quick and correct response 🙂

The method you mentioned is indeed much faster.

Best Regards,

Robert