Defer bulk peer identity restore after prioritizing contacts#604
Conversation
Restore active user contacts first during startup so important names are available quickly, then delay bulk peer identity restoration by 5 seconds. This reduces startup contention when the peer identity cache is large while preserving the existing restore pipeline. The bulk restore now skips identity hashes already restored from contacts and keeps the existing batched pagination for generic peers.
Greptile SummaryThis PR improves cold-start performance by prioritizing restoration of saved-contact identities before the full peer-identity bulk restore, and deferring the bulk restore by 5 seconds to reduce launch contention. The approach is sound and the measured improvement (~16-18 s → ~5 s splash) validates the change. The refactored Key findings:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as ColumbaApplication
participant CR as ContactRepository
participant SP as ServiceReticulumProtocol
participant Conv as ConversationRepository
App->>App: restorePeerIdentities()
App->>App: launch(Dispatchers.IO)
Note over App: Step 1 – Priority contacts
App->>CR: getRestorableContactIdentitiesForActiveIdentity()
CR-->>App: List<Pair<identityHash, publicKey>>
App->>SP: restorePeerIdentities(all contacts in ONE call)
SP-->>App: Result<Int> (count restored)
App->>App: build restoredContactIdentityHashes set (if success)
Note over App: 5-second delay
App->>App: delay(5000 ms)
Note over App: Step 2 – Bulk batched restore
loop Each batch of 500 raw entries
App->>Conv: getPeerIdentitiesBatch(500, offset)
Conv-->>App: List<Pair<peerHash, publicKey>>
App->>App: filter out alreadyRestoredIdentityHashes
alt batch not empty after filter
App->>SP: restorePeerIdentities(filtered batch)
SP-->>App: Result<Int>
end
App->>App: offset += 500
end
Last reviewed commit: ac0f9aa |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptile |
|
test failure is not reproducible locally, works for me. |
Thank you so much for this. I had this random issue so many times. The application logs was not helpful to make a good issue report here. |
| WHERE identityHash = :identityHash | ||
| AND status = :activeStatus | ||
| AND publicKey IS NOT NULL | ||
| ORDER BY isMyRelay DESC, isPinned DESC, lastInteractionTimestamp DESC, addedTimestamp DESC |
Summary
Problem
Cold start regressed badly on devices with a large peer cache. Investigation showed startup was eagerly restoring ~2500 peer identities before the app became usable, which kept the splash screen visible for far too long.
Solution
This keeps the existing restore pipeline but changes ordering and timing:
This preserves quick access to the names that matter most to the user while moving the expensive network-wide cache restore out of the critical startup path.
Validation
./gradlew :app:compileNoSentryDebugKotlin./gradlew :app:testNoSentryDebugUnitTest16-18ssplash before, now about5sNotes
The expected functional tradeoff is that some non-saved peers may temporarily display as raw hashes until the deferred bulk restore completes, while saved contacts should resolve first.