Commit Graph

63 Commits

Author SHA1 Message Date
Nora Trapp
1be27bbc10 Merge branch 'release/5.33.0' 2022-03-18 12:10:01 -07:00
Dimitris Apostolou
62724cf0be Fix typos 2022-03-18 11:31:06 -07:00
George Nachman
4886049d57 Batch fetch of user profiles.
Updates `UserProfileFinder` to have
`userProfiles(for:,transaction:)` that looks up
many profiles by either UUID or phone number.

Refactors the existing
`userProfile(for:,transaction:)` to use the batch
implementation.

Also adds Refinery.refineNonnilKeys to simplify a
repeating pattern where we need to fetch values
from a database where keys are nonnil. This
provides better type safety versus using
`refine(condition:,then:,otherwise:)` because the
closure can get non-optional keys as input.

Adds tests for the new user profile lookup code.
2022-03-17 14:32:17 -07:00
George Nachman
22c1cb8a22 Fetch phone numbers in a batch.
This is the first meaty part of optimizing
fetching display names.

Some contacts fall back to phone numbers as their
display names. This PR fetches them in a single
SQL query via
`OWSContactsManager.phoneNumbers(for:, transaction)`.

To achieve this, this PR introduces
`GRDBSignalAccountFinder.signalAccounts(for:,transaction:)`
to fetch many accounts at once.

In order to fetch many accounts at once, we need
to be able to fetch many values from a
ModelReadCache at once. So this PR introduces
`ModelReadCache.readValues(for:,transaction:)` and
`ModelReadCache.getValues(for:,transaction:,returnNilOnCacheMiss:)`.

Existing methods that operate on a single value
were refactored to use the batch methods.

This PR adds tests for this functionality, which
necessitated changing the visibility of various
private symbols and also improving the fake
profile manager to make it more configurable.

There's also a tiny optimization for Refinery to
avoid calling a closure that has no work to do.
This helps elide do-nothing SQL queries that would
otherwise have been introduced.
2022-03-17 12:46:33 -07:00
George Nachman
7702463524 Temporarily increase user profile cache size.
PR 2982 optimized
ConversationViewController.createGroupMembershipCollisionBannerIfNecessary`
that fetches user profiles off the main thread and
then, when that completes, uses them on the main
thread to find duplicate display names.

The optimization doesn't work for large groups.
Because `UserProfileReadCache` is backed by an
LRUCache with a maximum capacity of 32, there is
effectively no cache and profiles get fetched
twice.

The main purpose of this commit is to fix this
optimization for large groups without expanding
memory usage unnecessarily. While increasing the
LRU cache's size to 1000 (or some other arbitrary
value) would fix the problem very simply, my gut
tells me that we're going to keep running into
this problem.

Rather than pick an arbitrary "large enough"
value, this commit increases the cache size to be
just large enough for its intended purpose and to
keep it that size for just long enough to do its
job.

This commit introduces the concept of a "lease" on
a larger cache size. The cache's size is defined
as the largest of all its leases plus its
"regular" size (the size it was initialized with).
For now only the user profile cache uses it.
2022-02-11 13:20:12 -08:00
George Nachman
07d3ce2dec Increase the size of the sticker LRU cache.
We ship with 49 stickers and the previous cache size of 32 led to
thrasing every time a chat was opened.

Since sticker packs can be as large as 200 stickers and we hold three
pages in cache while the keyboard is open, increase the cache size for
the main app to 600. For the share extension, make it 64 to minimize
memory use while avoiding threashing.

The cost of this cache is just the sticker metadata (unique ID, emoji
description, etc.) so it won't make much difference in memory
utilization.
2022-02-02 13:07:01 -08:00
Matthew Chen
6162a85919 Reduce log chatter. 2021-10-26 13:08:42 -03:00
Matthew Chen
df2a714437 Clean up NSE logging. 2021-10-19 22:45:58 -03:00
Matthew Chen
30c21b0ac9 Disable model read caches in NSE. 2021-10-18 15:52:45 -03:00
Matthew Chen
5b2bfbdf15 Fire cross-process write notifications sync even if inactive. 2021-10-05 16:24:30 -03:00
Matthew Chen
fcb590829c Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
d4d96d698f Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
ab50c18c5a Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
03cc35819e Remove uiRead(). 2021-07-02 22:04:58 -03:00
Matthew Chen
78f88ad918 Set NSE cache sizes for ModelReadCache. 2021-06-30 16:11:55 -03:00
Matthew Chen
b9bc35e74b Apply LRUCache everywhere. 2021-06-30 16:01:08 -03:00
Matthew Chen
624f393efa Apply count limits to all NSCache, clean up caching. 2021-06-23 09:58:44 -03:00
Matthew Chen
82aab5ea12 Apply count limits to all NSCache, clean up caching. 2021-06-23 09:39:43 -03:00
Matthew Chen
86b8eb08b8 Remove YapDatabase.
Apply asset from design.

Fix rebase breakage.
2021-03-25 11:41:16 -03:00
Matthew Chen
d0cbf8cfd0 Rework dependency access. 2021-03-25 09:24:27 -03:00
Nora Trapp
54a327e269 Don't require cache evacuation to happen on the main thread to avoid deadlocks 2021-02-11 12:13:45 -08:00
Matthew Chen
645bd76bd5 Rework app readiness. 2021-02-04 09:55:39 -03:00
Matthew Chen
1be46d20bd Create a new GRDB storage adapter after grdb schema migrations. 2021-01-27 09:45:12 -03:00
Matthew Chen
34b6da7b2f Fix build warnings; fix crash around url session errors. 2021-01-23 23:10:54 -03:00
Matthew Chen
e77861ddbb Fix race in model read cache. 2021-01-21 20:36:47 -03:00
Matthew Chen
62856840da Clean up codebase. 2020-12-10 13:17:24 -03:00
Matthew Chen
111338b59d Rewrite conversation view. 2020-12-10 12:44:13 -03:00
Matthew Chen
6542f66324 Convert ModelReadCache assert into logging. 2020-10-15 17:44:12 -03:00
Matthew Chen
6170874486 Improve logging around model read cache assert. 2020-08-26 10:24:28 -03:00
Matthew Chen
4a1e6a07ea Fix edge case in model read cache. 2020-08-10 17:33:33 -03:00
Matthew Chen
6c569b1cf2 Fix edge case in model read cache. 2020-08-10 17:28:42 -03:00
Matthew Chen
ebb40f84a7 Respond to CR. 2020-08-06 22:35:37 -03:00
Matthew Chen
a8cf29c6c5 Ensure model cache robust to UUID mapping edge cases. 2020-08-06 22:27:45 -03:00
Matthew Chen
9daa11518d Ensure model cache robust to UUID mapping edge cases. 2020-08-06 22:27:45 -03:00
Matthew Chen
59f1e9a9d1 Ensure model cache robust to UUID mapping edge cases. 2020-08-06 22:27:45 -03:00
Matthew Chen
aff2c6684a Ensure model cache robust to UUID mapping edge cases. 2020-08-06 22:27:45 -03:00
Nora Trapp
d4e94fad03 evacuateAllCaches sync 2020-08-04 20:16:35 -07:00
Nora Trapp
e72214d6ea Fix an issue with SignalRecipient and SignalAccount ModelReadCaches 2020-08-04 19:57:07 -07:00
Matthew Chen
ed7206423e Avoid conflicts are keys for local user account and recipient. 2020-08-03 19:42:08 -03:00
Matthew Chen
0d96af0a38 Add explicit key type of model read cache. 2020-08-03 16:21:18 -03:00
Matthew Chen
01296a1ade Tweak ydb-to-grdb migration. 2020-07-30 13:51:17 -03:00
Nora Trapp
b55a013e62 A bear bones pass at updating the cache/ui after a uuid <-> phone number mapping change 2020-07-24 13:15:02 -07:00
Matthew Chen
ebce97faf8 Respond to CR. 2020-07-13 10:42:43 -03:00
Matthew Chen
b9fbb3da82 Evacuate model caches after device transfer. 2020-07-13 10:42:43 -03:00
Matthew Chen
3983974c53 Merge branch 'release/3.12.3' 2020-07-03 16:47:53 -03:00
Matthew Chen
51f35da8dd Preserve avatars. 2020-06-26 18:31:29 -03:00
Matthew Chen
059909bd1b Address sticker perf hotspots. 2020-06-23 10:07:18 -03:00
Matthew Chen
9e1704388d Disable model cache stats logging. 2020-06-18 14:17:23 -03:00
Matthew Chen
5b52b24486 Fix production build break. 2020-06-18 13:06:01 -03:00
Matthew Chen
9bc526b6bb Respond to CR. 2020-06-18 12:49:35 -03:00