Skip to content

Use multi-process DataStore instead of Preferences DataStore #6781

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 4 commits into from
Mar 20, 2025

Conversation

mrober
Copy link
Contributor

@mrober mrober commented Mar 19, 2025

Use multi-process DataStore instead of Preferences DataStore.

This change allows multiple processes to share the same datastore file safely. This reduces settings fetch to one per app run, not one per process.

Also updated the TimeProvider to provide an object with explicit time units. This will make time less error prone. Removed all instances of System.currentTimeMillis() from tests, making them deterministic.

Copy link
Contributor

github-actions bot commented Mar 19, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Contributor

github-actions bot commented Mar 19, 2025

Test Results

 1 034 files  + 17   1 034 suites  +17   35m 9s ⏱️ + 1m 3s
 5 851 tests  -  10   5 829 ✅  -   9  22 💤 ±0  0 ❌  - 1 
11 765 runs  +133  11 721 ✅ +134  44 💤 ±0  0 ❌  - 1 

Results for commit 4b978dc. ± Comparison against base commit af1fe93.

This pull request removes 15 and adds 5 tests. Note that renamed tests count towards both.
com.google.firebase.perf.session.SessionManagerTest ‑ setApplicationContext_logGaugeMetadata_afterGaugeMetadataManagerIsInitialized
com.google.firebase.perf.session.SessionManagerTest ‑ testGaugeMetadataIsFlushedOnlyWhenNewVerboseSessionIsCreated
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateDoesNothingDuringAppStart
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateDoesntGenerateNewSessionIdOnBackgroundState
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateDoesntMakeGaugeManagerLogGaugeMetadataOnBackgroundStateEvenIfSessionIsVerbose
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateDoesntMakeGaugeManagerLogGaugeMetadataOnForegroundStateIfSessionIsNonVerbose
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateGeneratesNewSessionIdOnBackgroundStateIfPerfSessionExpires
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateGeneratesNewSessionIdOnForegroundState
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateMakesGaugeManagerLogGaugeMetadataOnBackgroundAppStateIfSessionIsVerboseAndTimedOut
com.google.firebase.perf.session.SessionManagerTest ‑ testOnUpdateAppStateMakesGaugeManagerLogGaugeMetadataOnForegroundStateIfSessionIsVerbose
…
com.google.firebase.perf.session.SessionManagerTest ‑ setApplicationContext_initializeGaugeMetadataManager
com.google.firebase.perf.session.SessionManagerTest ‑ testUpdatePerfSessionMakesGaugeManagerStopCollectingGaugesIfSessionIsNonVerbose
com.google.firebase.perf.session.SessionManagerTest ‑ testUpdatePerfSessionMakesGaugeManagerStopCollectingGaugesWhenSessionsDisabled
com.google.firebase.perf.session.SessionManagerTest ‑ testUpdatePerfSessionStartsCollectingGaugesIfSessionIsVerbose
com.google.firebase.sessions.SessionDatastoreTest ‑ getCurrentSessionId_returnsLatest

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 19, 2025

Size Report 1

Affected Products

  • firebase-crashlytics

    TypeBase (af1fe93)Merge (ef2a3d4)Diff
    apk (aggressive)785 kB563 kB-222 kB (-28.3%)
    apk (release)6.65 MB6.11 MB-535 kB (-8.1%)
  • firebase-crashlytics-ktx

    TypeBase (af1fe93)Merge (ef2a3d4)Diff
    apk (aggressive)785 kB563 kB-222 kB (-28.3%)
    apk (release)6.65 MB6.11 MB-535 kB (-8.1%)
  • firebase-crashlytics-ndk

    TypeBase (af1fe93)Merge (ef2a3d4)Diff
    apk (aggressive / arm64-v8a)1.96 MB1.73 MB-225 kB (-11.5%)
    apk (aggressive / armeabi-v7a)1.43 MB1.21 MB-225 kB (-15.7%)
    apk (aggressive / x86)1.94 MB1.71 MB-225 kB (-11.6%)
    apk (aggressive / x86_64)2.00 MB1.78 MB-225 kB (-11.3%)
    apk (release / arm64-v8a)7.81 MB7.28 MB-537 kB (-6.9%)
    apk (release / armeabi-v7a)7.29 MB6.75 MB-537 kB (-7.4%)
    apk (release / x86)7.79 MB7.25 MB-537 kB (-6.9%)
    apk (release / x86_64)7.86 MB7.32 MB-537 kB (-6.8%)
  • firebase-perf

    TypeBase (af1fe93)Merge (ef2a3d4)Diff
    aar316 kB316 kB-81 B (-0.0%)
    apk (aggressive)1.63 MB1.51 MB-123 kB (-7.5%)
    apk (release)10.1 MB10.3 MB+262 kB (+2.6%)
  • firebase-perf-ktx

    TypeBase (af1fe93)Merge (ef2a3d4)Diff
    apk (aggressive)1.63 MB1.51 MB-123 kB (-7.5%)
    apk (release)10.1 MB10.3 MB+262 kB (+2.6%)
  • firebase-sessions

    TypeBase (af1fe93)Merge (ef2a3d4)Diff
    aar203 kB205 kB+2.49 kB (+1.2%)
    apk (aggressive)644 kB422 kB-223 kB (-34.6%)
    apk (release)6.31 MB5.78 MB-535 kB (-8.5%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/HGJy2XOMcG.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 19, 2025

Coverage Report 1

Affected Products

  • firebase-database

    Overall coverage changed from 50.21% (af1fe93) to 50.22% (ef2a3d4) by +0.01%.

    FilenameBase (af1fe93)Merge (ef2a3d4)Diff
    DefaultPersistenceManager.java74.76%75.73%+0.97%
  • firebase-inappmessaging

    Overall coverage changed from ? (af1fe93) to 39.03% (ef2a3d4) by ?.

    148 individual files with coverage change

    FilenameBase (af1fe93)Merge (ef2a3d4)Diff
    AbtIntegrationHelper.java?60.87%?
    AbtIntegrationHelper_Factory.java?0.00%?
    Action.java?76.47%?
    Analytics.java?0.00%?
    AnalyticsConstants.java?0.00%?
    AnalyticsEventsManager.java?85.19%?
    AnalyticsEventsModule.java?0.00%?
    AnalyticsEventsModule_ProvidesAnalyticsConnectorEventsFactory.java?0.00%?
    AnalyticsEventsModule_ProvidesAnalyticsEventsManagerFactory.java?0.00%?
    AnalyticsListener.java?0.00%?
    ApiClient.java?100.00%?
    ApiClientModule.java?0.00%?
    ApiClientModule_ProvidesApiClientFactory.java?0.00%?
    ApiClientModule_ProvidesDataCollectionHelperFactory.java?0.00%?
    ApiClientModule_ProvidesFirebaseAppFactory.java?0.00%?
    ApiClientModule_ProvidesFirebaseInstallationsFactory.java?0.00%?
    ApiClientModule_ProvidesSharedPreferencesUtilsFactory.java?0.00%?
    ApiClientModule_ProvidesTestDeviceHelperFactory.java?0.00%?
    AppComponent.java?0.00%?
    AppForeground.java?0.00%?
    ApplicationModule.java?0.00%?
    ApplicationModule_DeveloperListenerManagerFactory.java?0.00%?
    ApplicationModule_ProvidesApplicationFactory.java?0.00%?
    AppMeasurementModule.java?0.00%?
    AppMeasurementModule_ProvidesAnalyticsConnectorFactory.java?0.00%?
    AppMeasurementModule_ProvidesSubsriberFactory.java?0.00%?
    AutoValue_InstallationIdResult.java?33.33%?
    AutoValue_RateLimit.java?44.68%?
    BannerMessage.java?75.00%?
    Button.java?61.76%?
    CampaignAnalytics.java?33.22%?
    CampaignAnalyticsOrBuilder.java?0.00%?
    CampaignCache.java?0.00%?
    CampaignCacheClient.java?88.00%?
    CampaignCacheClient_Factory.java?0.00%?
    CampaignImpression.java?38.96%?
    CampaignImpressionList.java?39.25%?
    CampaignImpressionListOrBuilder.java?0.00%?
    CampaignImpressionOrBuilder.java?0.00%?
    CampaignMetadata.java?100.00%?
    CampaignProto.java?27.23%?
    CardMessage.java?78.48%?
    ClientAppInfo.java?35.79%?
    ClientAppInfoOrBuilder.java?0.00%?
    Clock.java?0.00%?
    CommonTypesProto.java?9.87%?
    DaggerAppComponent.java?0.00%?
    DaggerUniversalComponent.java?0.00%?
    DataCollectionHelper.java?87.50%?
    DataCollectionHelper_Factory.java?0.00%?
    DeveloperListenerManager.java?100.00%?
    DismissType.java?82.61%?
    DisplayCallbacksFactory.java?100.00%?
    DisplayCallbacksFactory_Factory.java?0.00%?
    DisplayCallbacksImpl.java?93.46%?
    EventType.java?76.19%?
    ExecutorsModule.java?0.00%?
    ExecutorsModule_ProvidesBackgroundExecutorFactory.java?0.00%?
    ExecutorsModule_ProvidesBlockingExecutorFactory.java?0.00%?
    ExecutorsModule_ProvidesLightWeightExecutorFactory.java?0.00%?
    ExperimentPayloadProto.java?6.05%?
    FetchEligibleCampaignsRequest.java?32.98%?
    FetchEligibleCampaignsRequestOrBuilder.java?0.00%?
    FetchEligibleCampaignsResponse.java?42.86%?
    FetchEligibleCampaignsResponseOrBuilder.java?0.00%?
    FetchErrorReason.java?52.17%?
    FiamAnalyticsConnectorListener.java?100.00%?
    FiamFetchService.java?0.00%?
    FirebaseAppScope.java?0.00%?
    FirebaseInAppMessaging.java?80.60%?
    FirebaseInAppMessagingCampaignAnalyticsProto.java?0.00%?
    FirebaseInAppMessagingClickListener.java?0.00%?
    FirebaseInAppMessagingContextualTrigger.java?0.00%?
    FirebaseInAppMessagingDismissListener.java?0.00%?
    FirebaseInAppMessagingDisplay.java?0.00%?
    FirebaseInAppMessagingDisplayCallbacks.java?100.00%?
    FirebaseInAppMessagingDisplayErrorListener.java?0.00%?
    FirebaseInAppMessagingImpressionListener.java?0.00%?
    FirebaseInAppMessagingRegistrar.java?0.00%?
    FirebaseInAppMessaging_Factory.java?0.00%?
    ForegroundFlowableModule.java?0.00%?
    ForegroundFlowableModule_ProvidesAppForegroundEventStreamFactory.java?0.00%?
    ForegroundNotifier.java?76.00%?
    GrpcChannelModule.java?0.00%?
    GrpcChannelModule_ProvidesGrpcChannelFactory.java?0.00%?
    GrpcChannelModule_ProvidesServiceHostFactory.java?0.00%?
    GrpcClient.java?100.00%?
    GrpcClientModule.java?0.00%?
    GrpcClientModule_ProvidesApiKeyHeadersFactory.java?0.00%?
    GrpcClientModule_ProvidesInAppMessagingSdkServingStubFactory.java?0.00%?
    GrpcClient_Factory.java?0.00%?
    ImageData.java?71.43%?
    ImageOnlyMessage.java?75.86%?
    ImpressionStorageClient.java?100.00%?
    ImpressionStorageClient_Factory.java?0.00%?
    ImpressionStore.java?0.00%?
    InAppMessage.java?24.24%?
    InAppMessageStreamManager.java?91.40%?
    InAppMessageStreamManager_Factory.java?0.00%?
    InAppMessaging.kt?0.00%?
    InAppMessagingSdkServingGrpc.java?45.95%?
    InstallationIdResult.java?100.00%?
    Logging.java?0.00%?
    MessagesProto.java?36.03%?
    MessageType.java?100.00%?
    MetricsLoggerClient.java?94.29%?
    ModalMessage.java?74.07%?
    ProgramaticContextualTriggers.java?0.00%?
    ProgrammaticContextualTriggerFlowableModule.java?0.00%?
    ProgrammaticContextualTriggerFlowableModule_ProvidesProgramaticContextualTriggersFactory.java?0.00%?
    ProgrammaticContextualTriggerFlowableModule_ProvidesProgramaticContextualTriggerStreamFactory.java?0.00%?
    ProgrammaticTrigger.java?0.00%?
    ProtoMarshallerClient.java?91.40%?
    ProtoMarshallerClient_Factory.java?0.00%?
    ProtoStorageClient.java?100.00%?
    ProtoStorageClientModule.java?0.00%?
    ProtoStorageClientModule_ProvidesProtoStorageClientForCampaignFactory.java?0.00%?
    ProtoStorageClientModule_ProvidesProtoStorageClientForImpressionStoreFactory.java?0.00%?
    ProtoStorageClientModule_ProvidesProtoStorageClientForLimiterStoreFactory.java?0.00%?
    ProviderInstaller.java?37.50%?
    ProviderInstaller_Factory.java?0.00%?
    ProxyAnalyticsConnector.java?67.95%?
    RateLimit.java?0.00%?
    RateLimiterClient.java?100.00%?
    RateLimiterClient_Factory.java?0.00%?
    RateLimitModule.java?0.00%?
    RateLimitModule_ProvidesAppForegroundRateLimitFactory.java?0.00%?
    RateLimitProto.java?52.69%?
    RenderErrorReason.java?82.61%?
    SchedulerModule.java?0.00%?
    SchedulerModule_ProvidesComputeSchedulerFactory.java?0.00%?
    SchedulerModule_ProvidesIOSchedulerFactory.java?0.00%?
    SchedulerModule_ProvidesMainThreadSchedulerFactory.java?0.00%?
    Schedulers.java?87.50%?
    Schedulers_Factory.java?0.00%?
    SharedPreferencesUtils.java?40.35%?
    SharedPreferencesUtils_Factory.java?0.00%?
    SystemClock.java?100.00%?
    SystemClockModule.java?0.00%?
    SystemClockModule_ProvidesSystemClockModuleFactory.java?0.00%?
    SystemClock_Factory.java?0.00%?
    TestDeviceHelper.java?100.00%?
    TestDeviceHelper_Factory.java?0.00%?
    Text.java?67.74%?
    TransportClientModule.java?0.00%?
    TransportClientModule_ProvidesMetricsLoggerClientFactory.java?0.00%?
    TriggeredInAppMessage.java?100.00%?
    UniversalComponent.java?0.00%?

  • firebase-messaging

    Overall coverage changed from 84.13% (af1fe93) to 84.02% (ef2a3d4) by -0.11%.

    FilenameBase (af1fe93)Merge (ef2a3d4)Diff
    Metadata.java41.27%36.51%-4.76%
  • firebase-ml-modeldownloader

    Overall coverage changed from ? (af1fe93) to 82.11% (ef2a3d4) by ?.

    36 individual files with coverage change

    FilenameBase (af1fe93)Merge (ef2a3d4)Diff
    AutoFirebaseMlLogEventEncoder.java?100.00%?
    AutoValue_FirebaseMlLogEvent.java?56.60%?
    AutoValue_FirebaseMlLogEvent_DeleteModelLogEvent.java?58.33%?
    AutoValue_FirebaseMlLogEvent_ModelDownloadLogEvent.java?56.96%?
    AutoValue_FirebaseMlLogEvent_ModelDownloadLogEvent_ModelOptions.java?60.00%?
    AutoValue_FirebaseMlLogEvent_ModelDownloadLogEvent_ModelOptions_ModelInfo.java?56.25%?
    AutoValue_FirebaseMlLogEvent_SystemInfo.java?54.93%?
    CustomModel.java?72.13%?
    CustomModelDownloadConditions.java?88.46%?
    CustomModelDownloadService.java?79.89%?
    CustomModelDownloadService_Factory.java?0.00%?
    CustomModel_Factory.java?0.00%?
    CustomModel_Factory_Impl.java?0.00%?
    DaggerModelDownloaderComponent.java?100.00%?
    DataTransportMlEventSender.java?100.00%?
    DataTransportMlEventSender_Factory.java?0.00%?
    DownloadType.java?100.00%?
    FirebaseMlException.java?100.00%?
    FirebaseMlLogEvent.java?97.92%?
    FirebaseMlLogger.java?88.89%?
    FirebaseMlLogger_Factory.java?0.00%?
    FirebaseModelDownloader.java?84.66%?
    FirebaseModelDownloaderRegistrar.java?100.00%?
    FirebaseModelDownloader_Factory.java?0.00%?
    ModelDownloader.kt?91.67%?
    ModelDownloaderComponent.java?25.00%?
    ModelDownloaderComponent_MainModule_AppPackageNameFactory.java?0.00%?
    ModelDownloaderComponent_MainModule_AppVersionCodeFactory.java?0.00%?
    ModelDownloaderComponent_MainModule_FirebaseOptionsFactory.java?0.00%?
    ModelDownloaderComponent_MainModule_PersistenceKeyFactory.java?0.00%?
    ModelFileDownloadService.java?88.46%?
    ModelFileDownloadService_Factory.java?0.00%?
    ModelFileManager.java?82.28%?
    ModelFileManager_Factory.java?0.00%?
    SharedPreferencesUtil.java?97.26%?
    SharedPreferencesUtil_Factory.java?0.00%?

  • firebase-perf

    Overall coverage changed from 70.62% (af1fe93) to 70.34% (ef2a3d4) by -0.28%.

    FilenameBase (af1fe93)Merge (ef2a3d4)Diff
    AppStateMonitor.java85.55%84.97%-0.58%
    CpuGaugeCollector.java92.77%93.83%+1.06%
    FirebasePerformance.java79.12%78.65%-0.47%
    FirebasePerformanceSessionSubscriber.kt?14.29%?
    GaugeManager.java98.40%98.37%-0.03%
    GaugeMetadataManager.java77.78%100.00%+22.22%
    PerfSession.java93.22%87.30%-5.92%
  • firebase-sessions

    Overall coverage changed from 66.63% (af1fe93) to 68.82% (ef2a3d4) by +2.19%.

    FilenameBase (af1fe93)Merge (ef2a3d4)Diff
    FirebaseSessionsComponent_MainModule_Companion_SessionDataStoreFactory.java?0.00%?
    FirebaseSessionsDependencies.kt85.71%92.00%+6.29%
    SessionConfigs.kt?95.45%?
    SessionDatastore.kt3.33%78.13%+74.79%
    SessionGenerator.kt90.91%95.45%+4.55%
    SettingsCache.kt93.55%89.29%-4.26%
    SettingsCacheImpl_Factory.java?0.00%?
    TimeProvider.kt0.00%60.00%+60.00%
    UuidGenerator.kt0.00%100.00%+100.00%

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/FoQCc976US.html

@mrober mrober requested review from tejasd and themiswang March 19, 2025 15:03
@mrober mrober changed the base branch from main to fireperf-aqs March 19, 2025 19:21
Copy link
Contributor

@themiswang themiswang left a comment

Choose a reason for hiding this comment

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

LGTM, as discussed let's followup on double updating for multi-processes later.

@mrober mrober merged commit 62508f2 into fireperf-aqs Mar 20, 2025
260 of 262 checks passed
@mrober mrober deleted the mrober/datastoredi branch March 20, 2025 16:28
mrober added a commit that referenced this pull request Mar 27, 2025
Use multi-process DataStore instead of Preferences DataStore.

This change allows multiple processes to share the same datastore file
safely. This reduces settings fetch to one per app run, not one per
process.

Also updated the TimeProvider to provide an object with explicit time
units. This will make time less error prone. Removed all instances of
`System.currentTimeMillis()` from tests, making them deterministic.
themiswang pushed a commit that referenced this pull request Mar 31, 2025
Use multi-process DataStore instead of Preferences DataStore.

This change allows multiple processes to share the same datastore file
safely. This reduces settings fetch to one per app run, not one per
process.

Also updated the TimeProvider to provide an object with explicit time
units. This will make time less error prone. Removed all instances of
`System.currentTimeMillis()` from tests, making them deterministic.
tejasd pushed a commit that referenced this pull request Apr 1, 2025
Use multi-process DataStore instead of Preferences DataStore.

This change allows multiple processes to share the same datastore file
safely. This reduces settings fetch to one per app run, not one per
process.

Also updated the TimeProvider to provide an object with explicit time
units. This will make time less error prone. Removed all instances of
`System.currentTimeMillis()` from tests, making them deterministic.
mrober added a commit that referenced this pull request Apr 7, 2025
Use multi-process DataStore instead of Preferences DataStore.

This change allows multiple processes to share the same datastore file
safely. This reduces settings fetch to one per app run, not one per
process.

Also updated the TimeProvider to provide an object with explicit time
units. This will make time less error prone. Removed all instances of
`System.currentTimeMillis()` from tests, making them deterministic.
mrober added a commit that referenced this pull request Apr 15, 2025
Use multi-process DataStore instead of Preferences DataStore.

This change allows multiple processes to share the same datastore file
safely. This reduces settings fetch to one per app run, not one per
process.

Also updated the TimeProvider to provide an object with explicit time
units. This will make time less error prone. Removed all instances of
`System.currentTimeMillis()` from tests, making them deterministic.
@firebase firebase locked and limited conversation to collaborators Apr 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants