Skip to content

improvement(startup): split into methods and add timing#20593

Open
david-allison wants to merge 22 commits intoankidroid:mainfrom
david-allison:refactor-app-create
Open

improvement(startup): split into methods and add timing#20593
david-allison wants to merge 22 commits intoankidroid:mainfrom
david-allison:refactor-app-create

Conversation

@david-allison
Copy link
Copy Markdown
Member

@david-allison david-allison commented Mar 26, 2026

Note

Assisted-by: Claude Opus 4.6 - one commit:

setup("setupX") { setupX() } // move the setup() call inside setupX

Purpose / Description

I wanted a common method which would handle startup:

  • So we could have one place where fatal and nonfatal initlilization errors occurred
  • So we did not need to worry about methods throwing and hard-crashing on startup
  • So we could profile startup times and be sure they're reasonable

Fixes

Approach

  • introduce setup, which performs the logging & timing of methods
  • Define dependencies using an object: AnkiContext or CrashReportingContext, and require their use via context providers
    context(_: AnkiContext)
    private fun initializeAnkiDroidDirectory() {}

    val anki = AnkiContext.apply { setupAnkiBackend() }
    with(anki) { initializeAnkiDroidDirectory() }
  • Extract each setup operation into a method
  • Combine and reorder methods where they make sense

How Has This Been Tested?

executed setupLogging in 11.416833ms
executed setupUsageAnalytics in 94.884708ms
executed performStartupLogging in 3.251458ms
executed setupContextMenus in 1.153625ms
executed makeBackendUsable in 143us
executed setupNotifications in 5.957541ms
executed setupAppLifecycleObserver in 579.041us
executed setupBackendChangeManager in 10.660333ms
executed setupWebView in 992.291us
executed setupBackend in 774.709us
executed initializeAnkiDroidDirectory in 1.840709ms
executed setupDayRollover in 1.921333ms
executed setupLifecycleLogging in 181.791us
executed setupTextToSpeech in 2.633416ms

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison added squash-merge A squash & force push is required. The PR author may do this to speed up the merge process. Blocked by dependency Currently blocked by some other dependent / related change labels Mar 26, 2026
@david-allison david-allison changed the title refactor: AnkiDroidApp.onCreate improvement(startup): split into method and add timing Mar 26, 2026
@david-allison david-allison force-pushed the refactor-app-create branch 2 times, most recently from c1248b9 to b3256d6 Compare March 29, 2026 03:19
@david-allison david-allison added Needs Review and removed Blocked by dependency Currently blocked by some other dependent / related change labels Mar 29, 2026
@david-allison david-allison marked this pull request as ready for review March 29, 2026 03:21
@david-allison david-allison changed the title improvement(startup): split into method and add timing improvement(startup): split into methods and add timing Apr 6, 2026
Cleaner to have them inside the methods themselves

We will update 'setup' later to handle 20168

Issue 20168

Assisted-by: Calude Opus 4.6
 move 'setup' calls inside the methods, but use a block body,
 rather than '= setup' syntax
@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author Next version Changes to be merged in the next version, to keep the current release stable. labels Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Has Conflicts Needs Author Reply Waiting for a reply from the original author Needs Review Next version Changes to be merged in the next version, to keep the current release stable. squash-merge A squash & force push is required. The PR author may do this to speed up the merge process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant