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()
Change-Id: Id44886143fb2910955294341d4938d638c72f7f9
Signed-off-by:
Myles Watson <mylesgw@google.com>
Loading
Please register or sign in to comment