Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30e2e5e2 authored by Niklas Brunlid's avatar Niklas Brunlid Committed by Steve Kondik
Browse files

Reduce GC in Bluetooth application

During OPP transfer, the Bluetooth application uses a ContentProvider
to keep track of how many bytes have been transferred. An update()
is called every 64Kb and in turn causes a couple of query(). One of
the listeners updates a notification. All of this causes a lot of
small memory allocations and means that the GC has to clean up a lot
of objects during transfer.
Partly fixed by only calling update() every percent of transfer
instead of every 64Kb block, which means it works best on large
files.

Change-Id: Ia24b5e460fd52ed066867887ff6d22c579ec8e7e
parent db3d9d70
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -432,6 +432,10 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                        }
                    }

                    final int onePercent = Math.max((int)(fileInfo.mLength / 100), 1);
                    int percentPosition = 0;
                    updateValues = new ContentValues();

                    while (!mInterrupted && okToProceed && (position != fileInfo.mLength)) {
                        {
                            if (V) timestamp = System.currentTimeMillis();
@@ -448,15 +452,21 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession {
                                okToProceed = false;
                            } else {
                                position += readLength;
                                percentPosition += readLength;
                                if (V) {
                                    Log.v(TAG, "Sending file position = " + position
                                            + " readLength " + readLength + " bytes took "
                                            + (System.currentTimeMillis() - timestamp) + " ms");
                                }
                                updateValues = new ContentValues();

                                // Limit the number of update() calls to once per percent as it is
                                // expensive.
                                if (percentPosition >= onePercent) {
                                    updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                                    mContext1.getContentResolver().update(contentUri, updateValues,
                                            null, null);
                                    percentPosition = percentPosition % onePercent;
                                }
                            }
                        }
                    }
+11 −3
Original line number Diff line number Diff line
@@ -444,6 +444,10 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
            int readLength = 0;
            long timestamp = 0;
            try {
                ContentValues updateValues = new ContentValues();
                final int onePercent = Math.max((int)(fileInfo.mLength / 100), 1);
                int percentPosition = 0;

                while ((!mInterrupted) && (position != fileInfo.mLength)) {

                    if (V) timestamp = System.currentTimeMillis();
@@ -457,6 +461,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen

                    bos.write(b, 0, readLength);
                    position += readLength;
                    percentPosition += readLength;

                    if (V) {
                        Log.v(TAG, "Receive file position = " + position + " readLength "
@@ -464,9 +469,12 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen
                                + (System.currentTimeMillis() - timestamp) + " ms");
                    }

                    ContentValues updateValues = new ContentValues();
                    // Limit the number of update() calls to once per percent as it is expensive.
                    if (percentPosition >= onePercent) {
                        updateValues.put(BluetoothShare.CURRENT_BYTES, position);
                        mContext.getContentResolver().update(contentUri, updateValues, null, null);
                        percentPosition = percentPosition % onePercent;
                    }
                }
            } catch (IOException e1) {
                Log.e(TAG, "Error when receiving file");