Repository navigation
perf: optimize cold-start journal loading and add startup stage metrics - #191
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
Note
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 3 findings. Devin automatically fixed all 3 findings.
Fixed by Devin (3)
- Host formatting breaks the boundary test — Restored single-line JournalRuntimeHost(platform: platform, ...) call in swift/JournalRuntimeHost.swift and verified test/source_boundary_test.exe passes.
- Early account lookup risks skipping sign-in — Added initial: true to both platform.authenticationRequired and platform.localAccountAvailable onChange modifiers in JournalHost so an early account lookup resolving before mount still opens the automatic sign-in sheet.
- Extra queries delay the startup timeline — Reverted the 12-root initial-slice split in start_feed_scan so initial 30-root loads complete in a single verified batch without an extra Timeline.Roots round-trip before the startup feed_loaded gate opens.
…r_capacity across resident graphs
…ndoff, and shared overlay SQLite open
There was a problem hiding this comment.
Note
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 1 finding. Devin did not fix them (the PR is muted); it is left for you to triage below.
| private var visible: Bool { | ||
| #if os(iOS) | ||
| active && (initial ? clock?.elapsed == true : loading) | ||
| #else | ||
| active && (loading || (initial && clock?.elapsed == true)) | ||
| #endif | ||
| } |
There was a problem hiding this comment.
🟡 Missing progress during iOS startup
When the startup reducer signals loading during a cold graph restore, visible ignores it. The loading surface shows no progress until the five-second launch deadline, even if the restore finishes before then.
Learn more
The startup reducer owns the loading state once the application is running. The startup timer triggers that state after 100 ms of waiting, and manager_props passes it to the startup screen. The native startup renderer forwards it as loading. The five-second native deadline also applies before that state exists, but it need not override an explicit loading signal once the application has sent one.
Example: Open the app on an iPhone with a saved graph that takes two seconds to restore. The startup reducer requests a loading indicator while the graph opens, but the iOS startup surface never displays it before the timeline replaces it.
Recommended fix: Keep the native deadline as a fallback for initial surfaces without an explicit loading signal. Honor loading whenever the surface is active, including during the first attempt.
| private var visible: Bool { | |
| #if os(iOS) | |
| active && (initial ? clock?.elapsed == true : loading) | |
| #else | |
| active && (loading || (initial && clock?.elapsed == true)) | |
| #endif | |
| } | |
| private var visible: Bool { active && (loading || (initial && clock?.elapsed == true)) } |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Note
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 2 findings. Devin did not fix them (the PR is muted); all 2 findings are left for you to triage below.
| .onChange(of: properties.canChoose == true && properties.active == true && context.isUserInteractionEnabled && startupClock?.phase == .pickerRequested, initial: true) { _, eligible in | ||
| if eligible { startupClock?.deliverManagerPicker { | ||
| JournalExtensions.emit(context: context, payload: Data("choose-graph".utf8)) | ||
| } } |
There was a problem hiding this comment.
🔍 Automatic picker handoff lacks iOS coverage
The clock test calls deliverPicker directly. The manager test injects the native event, bypassing the SwiftUI handoff. Neither verifies that a pending request opens the picker and clears when it appears.
Was this helpful? React with 👍 or 👎 to provide feedback.
| if let action { action } | ||
| else { Text("Opening graph picker…") } |
There was a problem hiding this comment.
🔍 Pending picker loses its status message
While a picker request is pending, JournalStartupLoadingSurface treats the manager’s empty action column as a visible control. The manager supplies that column before graph selection is available, leaving neither a status message nor an action.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Optimize cold-start journal loading across SQLite storage, overlay DB open, feed planning, eager Swift runtime bootstrap, SwiftUI host mounting, and
JournalListfirst-frame layout, and add structured stage-level startup timing logs (OSLogcom.logseq.journal:startupandjournal-startup:stderr JSON).Key Changes
logseq_db_storage/lib/logseq_sqlite_storage.ml,mutation_receipt_store.ml,logseq_overlay_db/lib/database.ml):WHERE typeof(addr) <> 'integer' OR addr < 0 LIMIT 1full-table scan with primary-key index probe (WHERE addr < 0 LIMIT 1) and reuse preparedkvsstatements with integer binding.open_ownedacross outbox read, receipt initialization, and legacy outbox migration instead of opening 3 separate connections.CREATE TABLE IF NOT EXISTSinmutation_receipt_storewhen tables already exist and skip redundant outbox migration when already migrated.authoritative_tree_candidateto a single EAVT scan while preserving single-valued attribute rejection.app/journal_graph_feed_plan.ml,test/journal_graph_runtime_locality_test.ml):Preview_childrenrequests concurrently using a bounded queue (max_concurrent_root_previews = 8) instead of strictly serial root-by-root round-trips through Worker → MainActor → LUI, staying withindispatcher_capacityacross concurrent resident graphs.swift/App.swift,swift/JournalRuntimeHost.swift,swift/JournalRuntime.swift,apple-tests/warm-start/JournalWarmStartAcceptance.swift):JournalRuntimeeagerly inApp.init()(and the warm-start probe) so OCaml/SQLite/feed work overlaps iOS window creation, handing the prestarted runtime toJournalRuntimeHostand observing initial account state (initial: true) onJournalHost.waitForStartupContent(timeoutMilliseconds: 200)soLUISwiftUIRootwaits forjournal-list(or a ready non-timeline interactive screen) instead of mounting the loading UI early and starving the worker pump on the MainActor.JournalListfirst-frame overhead (swift/JournalList.swift):UIScrollViewsynchronously inresolveIfNeeded()and invokepresentationLayoutsynchronously inTopScroll.didLayout()to remove an extra async turn before initial cover dismissal.AnyViewand skip attaching.contextMenumodifiers when a row has no context menu actions.swift/JournalRuntime*.swift,app/application.ml,logseq_db_worker,logseq_sync,logseq_overlay_db):timelinePresented(ignoringSys_errorwhen stderr is unwritable).iOS Simulator Measurements (iPhone 17 / iOS 26.5, 500 roots / 35 children / 7 days)
reopen: 25.0 ms → 5.47 ms (median)overlay.open_owned: 11.85 ms → 5.81–7.38 ms (median 6.56 ms)Load_feed(30 initial roots): 107.2 ms → 44.5 msapp.timeline_presented(in-app): 664 ms → 240–268 ms (median 260 ms, ~2.55× faster)Before vs After Cold-Start Comparison
Validation
dune exec test/source_boundary_test.exe -- .(passed)dune exec test/application_view_test.exe -- -q(232/232 passed)dune exec test/journal_graph_runtime_locality_test.exe -- -q(229/229 passed)dune exec logseq_overlay_db/test/test_overlay_storage.exe -- -q(106/106 passed)dune exec test/logseq_db_worker_application_integration_test.exe -- -q(10/10 passed)Link to Devin session: https://app.devin.ai/sessions/948ee74c8f524740a7082f8c0b742c90
Open in Devin Desktop: https://app.devin.ai/desktop/session/948ee74c8f524740a7082f8c0b742c90?variant=devin
Requested by: @tiensonqin
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work