OSDN Git Service

RemoteDevices: Optimize adding new remote devices
authorMyles Watson <mylesgw@google.com>
Fri, 15 Jul 2016 00:43:11 +0000 (17:43 -0700)
committerMyles Watson <mylesgw@google.com>
Fri, 12 Aug 2016 13:56:01 +0000 (06:56 -0700)
commit619e48d1c82ff9b0ef25dee9ef3c391c41a61a58
tree6ee6d3100661511c1d1e92b3985ee8d262217cdd
parenta1c7315ed05df04599e7cdc5f4bcf7d3ec8d3392
RemoteDevices: Optimize adding new remote devices

RemoteDevices keeps track of the Bluetooth devices which have been
seen since the Bluetooth stack was initialized.  Each time a remote
device is discovered, it is added to a hash map.  When the size of the
hash map grows beyond a few hundred devices, the performance degrades.

This patch:
 - creates the address string once per search
  reducing the average search time with 300 devices from ~20ms to ~1ms
 - uses the hash of the address string to search
  further reducing the time with 1200 devices from ~2ms to ~1ms

HashMap<BluetoothDevice, DeviceProperties> became
 HashMap<String, DeviceProperties>

mDevice now stores the BluetoothDevice in each instance of
DeviceProperties.

TEST: Used System.nanoTime() to measure the elapsed time of
      getDeviceProperties()
Bug: 30828758

Change-Id: Id44886143fb2910955294341d4938d638c72f7f9
Signed-off-by: Myles Watson <mylesgw@google.com>
(cherry picked from commit 1fb90c4f25ba33b0f951e6ac092d05f85d355e2f)
src/com/android/bluetooth/btservice/RemoteDevices.java