Skip to content

Cache FID to avoid multiple disk reads. #1571

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

Merged
merged 2 commits into from
May 20, 2020
Merged

Cache FID to avoid multiple disk reads. #1571

merged 2 commits into from
May 20, 2020

Conversation

ankitaj224
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes Override cla label May 18, 2020
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 18, 2020

Binary Size Report

Affected SDKs

  • firebase-common

    Type Base (b26d198) Head (50268b61) Diff
    aar ? 34.7 kB ? (?)
    apk (aggressive) ? 82.5 kB ? (?)
    apk (debug) ? 770 kB ? (?)
    apk (release) ? 636 kB ? (?)
  • firebase-components

    Type Base (b26d198) Head (50268b61) Diff
    aar ? 34.5 kB ? (?)
    apk (aggressive) ? 11.0 kB ? (?)
    apk (debug) ? 35.9 kB ? (?)
    apk (release) ? 25.4 kB ? (?)
  • firebase-installations

    Type Base (b26d198) Head (50268b61) Diff
    aar ? 57.6 kB ? (?)
    apk (aggressive) ? 84.3 kB ? (?)
    apk (debug) ? 794 kB ? (?)
    apk (release) ? 657 kB ? (?)
  • firebase-installations-interop

    Type Base (b26d198) Head (50268b61) Diff
    aar ? 7.51 kB ? (?)
    apk (aggressive) ? 61.7 kB ? (?)
    apk (debug) ? 744 kB ? (?)
    apk (release) ? 616 kB ? (?)

Test Logs

Notes

Head commit (50268b61) is created by Prow via merging commits: b26d198 3c974c4.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 18, 2020

Coverage Report

Affected SDKs

  • firebase-installations

    SDK overall coverage changed from ? (b26d198) to 58.06% (50268b61) by ?.

    Click to show coverage changes in 18 files.
    Filename Base (b26d198) Head (50268b61) Diff
    AutoValue_InstallationResponse.java ? 42.86% ?
    AutoValue_PersistedInstallationEntry.java ? 61.18% ?
    AutoValue_TokenResult.java ? 45.65% ?
    AwaitListener.java ? 0.00% ?
    CrossProcessLock.java ? 51.85% ?
    FirebaseInstallationServiceClient.java ? 5.50% ?
    FirebaseInstallations.java ? 97.84% ?
    FirebaseInstallationsException.java ? 75.00% ?
    FirebaseInstallationsRegistrar.java ? 100.00% ?
    GetAuthTokenListener.java ? 90.00% ?
    IidStore.java ? 44.78% ?
    InstallationResponse.java ? 100.00% ?
    PersistedInstallation.java ? 96.77% ?
    PersistedInstallationEntry.java ? 100.00% ?
    RandomFidGenerator.java ? 20.00% ?
    StateListener.java ? 0.00% ?
    TokenResult.java ? 100.00% ?
    Utils.java ? 100.00% ?

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (50268b61) is created by Prow via merging commits: b26d198 3c974c4.

Copy link
Contributor

@andirayo andirayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to do all the logic inside of #doGetId:

  private String doGetId() {
    // only read FID once from disk per session. Note: cachedFid will be reset if FID is deleted.
    if (cachedFid != null) {
        return cachedFid;
    }
    PersistedInstallationEntry prefs = getPrefsWithGeneratedIdMultiProcessSafe();
    networkExecutor.execute(() -> doNetworkCall(false));
    
    if (prefs.status == REGISTERED) {  // pseudo-code
        cachedFid = prefs.getFirebaseInstallationId();
    }
    return prefs.getFirebaseInstallationId();
  }

@ankitaj224
Copy link
Contributor Author

I would recommend to do all the logic inside of #doGetId:

  private String doGetId() {
    // only read FID once from disk per session. Note: cachedFid will be reset if FID is deleted.
    if (cachedFid != null) {
        return cachedFid;
    }
    PersistedInstallationEntry prefs = getPrefsWithGeneratedIdMultiProcessSafe();
    networkExecutor.execute(() -> doNetworkCall(false));
    
    if (prefs.status == REGISTERED) {  // pseudo-code
        cachedFid = prefs.getFirebaseInstallationId();
    }
    return prefs.getFirebaseInstallationId();
  }

LGTM. PTAL - updated the PR.

@ankitaj224 ankitaj224 requested a review from andirayo May 19, 2020 17:40
@ankitaj224 ankitaj224 merged commit 0bb76d3 into blockID May 20, 2020
ankitaj224 added a commit that referenced this pull request May 20, 2020
* Dropping guava and appcompat dependency from FIS SDK.

* Fix OverlappingFileLockException.

Access the data shared by multiple threads only after acquiring cross-process and multi-thread safe locks.

* Completing getId call with the disk reads on the caller thread.

Also, fixing delete API to access persisted FID using cross process
safe locks.

* Addressing Fred's comments

* Remove unused variable

* Cache FID to avoid multiple disk reads. (#1571)

* Cache FID to avoid multiple disk reads.

* Addressing Rayo's comments.

* Addressing Rayo's comments
@firebase firebase locked and limited conversation to collaborators Jun 20, 2020
@kaibolay kaibolay deleted the cachheFID branch September 14, 2022 17:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Override cla size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants