Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for expected emitters has bad performance #47

Open
Helium314 opened this issue Feb 28, 2022 · 0 comments
Open

Checking for expected emitters has bad performance #47

Helium314 opened this issue Feb 28, 2022 · 0 comments

Comments

@Helium314
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant