Skip to content

Checking for expected emitters has bad performance #47

Description

@Helium314

At the end of each reporting period, a check for missing emitters is done:

// If we are dealing with very movable emitters, then try to detect ones that
// have moved out of the area. We do that by collecting the set of emitters
// that we expected to see in this area based on the GPS and our own location
// computation.
Set<RfIdentification> expectedSet = new HashSet<>();
if (weightedAverageLocation != null) {
emitterCache.sync(); // getExpected() ends bypassing the cache, so sync first
for (RfEmitter.EmitterType etype : RfEmitter.EmitterType.values()) {
expectedSet.addAll(getExpected(weightedAverageLocation, etype));
}
if (gpsLocation != null) {
for (RfEmitter.EmitterType etype : RfEmitter.EmitterType.values()) {
expectedSet.addAll(getExpected(gpsLocation.getLocation(), etype));
}
}
}

This makes sense, but is rather slow and not strictly necessary (mostly to clean old data from DB).
Performance of this check with a large database is actually so bad that DejaVu may end up as most battery consuming app (according to battery usage in Android settings).

Proposed improvements:

  • getExpected() queries emitters from DB by latitude, longitude and type, so we should add an index on latitude, longitude and type to the database.
  • we get all types of emitters from DB, with the purpose of decreasing trust of the ones we expect, but could not find. But EmitterType.MOBILE has decrTrust 0, so trust cannot be decreased. There is no point in fetching MOBILE emitters from DB.
  • emitterCache.sync(); is not necessary: the only emitters that are not in DB (or are not updated) are emitters we have in seenSet, and the only purpose of the expected check is decreasing trust of expected emitters that are not in the seenSet.
  • (+some more potential improvements that require more changes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions