diff options
author | Niklas Brunlid <niklas.brunlid@sonyericsson.com> | 2010-09-30 13:30:53 +0200 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2011-03-08 19:46:46 -0500 |
commit | 30e2e5e2e65186cc12967dad39dd344c729cb976 (patch) | |
tree | 490c519546ef1ff7468945ebf516824bc7fa6310 | |
parent | db3d9d70300de3adc61ea83ef5122206b7e15d53 (diff) | |
download | android_packages_apps_Bluetooth-cm-7.0.3.tar.gz android_packages_apps_Bluetooth-cm-7.0.3.tar.bz2 android_packages_apps_Bluetooth-cm-7.0.3.zip |
Reduce GC in Bluetooth applicationcm-7.0.3cm-7.0.2.1cm-7.0.1cm-7.0.0
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
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java | 18 | ||||
-rw-r--r-- | src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java | 14 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 6efac93de..521c46a5d 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -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(); - updateValues.put(BluetoothShare.CURRENT_BYTES, position); - mContext1.getContentResolver().update(contentUri, updateValues, - null, null); + + // 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; + } } } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index cb292c1b1..2ed021933 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -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(); - updateValues.put(BluetoothShare.CURRENT_BYTES, position); - mContext.getContentResolver().update(contentUri, updateValues, null, null); + // 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"); |