Files
buzz/mobile/pubspec.yaml
Tom Brow b0e55606f2 perf(mobile): stop following presence for people no longer shown (#9480)
[#9444](https://github.com/block/buzz/pull/9444) narrows the live
presence subscription (kind 20001) to the people the app has shown this
session. That set only grows, so scrolling through a long DM list or
opening many profiles keeps receiving presence for people who are no
longer on screen, and each new person reopens the subscription with
everyone seen so far. This was raised in [Jude's
review](https://github.com/block/buzz/pull/9444#pullrequestreview-5896221680).

With this change, presence follows only who is on screen now:

- `track` returns a release callback. DM rows and profile sheets release
when they unmount. Counts are per person, so someone shown in a DM row
and an open profile sheet stays followed until both are gone.
- A person nobody has shown for at least 30 seconds is retired: dropped
from the tracked set and the cache, and the live subscription is
replaced with one for the people still shown. A sweep every 30 seconds
retires everyone whose own 30 seconds are up, so each person stays
followed for 30 to 60 seconds after their release and the subscription
narrows at most once per 30 seconds. Scrolling back within 30 seconds
keeps the current subscription.
- A read that started before someone was retired doesn't fill in their
presence if they are shown again; they wait for a read of their own.
- When nobody is shown, the stream closes, and the next person shown
opens a new one immediately.
- Switching communities keeps following people still on screen, instead
of dropping everyone.

### Regressions

- **Mention picker ranking.** The picker reads the presence cache
without tracking anyone itself, so it ranks by presence only for people
currently on screen (before, also for anyone shown earlier in the
session). Keeping a retired person's last value would show stale
presence, which is worse.
- **Dot pop-in.** A retired person's dot is missing when they come back
(scrolling back after 30 seconds, or switching the Home filter to Solo
and back after 30 seconds) until the replacement subscription is ready
and their snapshot read returns. On a slow link that can take seconds.
Before, the dot stayed for the whole session.
- **Network.** A retirement costs one replacement REQ and a CLOSE, at
most once per 30 seconds of scrolling. A person shown again after being
retired costs one snapshot read, the same as the first time they were
shown.
- **Reliability.** Narrowing uses #9444's replacement path (the old
stream stays until the new one is ready), so a failed narrowing keeps
the wider stream and the poll retries it.

### Validation

iPhone 12 mini on Builderlab (measured on
[bda9e214f](https://github.com/block/buzz/commit/bda9e214f), before the
sweep change), cold launch, scroll the Home list to the bottom and back
to the top, then 60 s idle:

| | #9444 head | This PR |
| --- | --- | --- |
| Live presence authors at the end | 37 (only grows) | 1 (37 at the
bottom, then 11, then 1) |
| Presence events while idle (60 s) | 29 (10.7 KB) | 0 |
| Presence REQs during the run | 36 | 37 |

Presence dots still show on the DM rows visible at the bottom of the
list. Both heads still reopen the subscription once per newly shown
person while scrolling (36 swaps for 37 people); batching those during a
fling would be the next bound, and is not part of this PR.

Added tests:
- A person shown in two places stays followed until both release.
Released people leave the subscription only after the delay, and their
late live events are ignored.
- Showing someone again within the delay keeps the same subscription and
their cached presence.
- Releasing everyone closes the stream, and the next person shown gets a
new subscription and a snapshot read right away.
- Scrolling 500 rows past a window of 10 leaves a subscription for
exactly the last 10, with exactly two replacement opens after scrolling
stops (the sweeps 30 s apart).
- A person released 29 seconds after another keeps their subscription
and cached presence when the first one is retired, and is retired at a
later sweep.
- A person retired while their snapshot is in flight stays absent.
- A read started a second before someone is retired doesn't fill them in
once they're shown again; the other people in that read keep their
results, and the person's own read does.
- Production seam: removing a DM row from the Home list stops following
that person after the delay (the stream closes and the cache empties).

Each guard was mutation-checked: removing it fails at least one of these
tests.

Changed test: the community-switch snapshot test now expects people
still on screen to be read in the new community.

Full mobile suite: 4857 passed, 71 skipped (on ca0066de3, after rebasing
onto main).

---------

Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
2026-11-16 15:13:36 -08:00

114 lines
3.0 KiB
YAML

name: buzz
description: Buzz mobile client
publish_to: 'none'
version: 0.0.0+1
environment:
sdk: ^3.11.4
flutter: ">=3.47.9"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.8
# Grapheme-cluster segmentation, for deciding whether a message body is
# nothing but emoji. Already present transitively via the Flutter SDK;
# declared here because we import it directly.
characters: ^1.4.0
# Fakeable time for presence release ages. Already present transitively via
# the Flutter SDK; declared here because we import it directly.
clock: ^1.1.2
hooks_riverpod: ^3.0.3
flutter_hooks: ^0.21.3
http: ^1.4.0
# Native HTTP transports, NSURLSession on iOS and Cronet on Android: HTTP/2
# and native gzip. See lib/shared/http/app_http_client.dart.
cronet_http: ^1.10.1
cupertino_http: ^3.1.0
jni: ^1.1.0
objective_c: ^9.5.0
crypto: ^3.0.7
flutter_secure_storage: ^10.0.0
flutter_svg: ^2.2.4
mobile_scanner: ^7.0.0
shared_preferences: ^2.5.5
web_socket_channel: ^3.0.1
connectivity_plus: ^7.0.0
nostr: ^2.0.0
buzz_secp256k1:
path: packages/buzz_secp256k1
pointycastle: ^4.0.0
url_launcher: ^6.3.2
gpt_markdown: 1.3.4
highlight: ^0.7.0
intl: ^0.20.2
uuid: ^4.5.1
file_selector: ^1.1.0
camera: ^0.12.0+2
image_picker: ^1.1.2
image: ^4.8.0
google_mlkit_selfie_segmentation: ^0.11.0
photo_manager: ^3.11.0
video_player: ^2.10.1
just_audio: ^0.10.6
record: ^6.2.1
package_info_plus: ^10.0.0
app_badge_plus: ^1.2.10
app_links: ^6.4.0
scrollable_positioned_list: ^0.3.8
open_filex: ^4.7.0
path_provider: ^2.1.6
share_plus: ^13.3.0
local_auth: ^3.0.2
unorm_dart: ^0.3.3
duo_kit: 0.1.1
flutter_cache_manager: ^3.5.0
file: ^7.0.1
path: ^1.9.1
dev_dependencies:
leak_tracker: ^11.0.2
shared_preferences_platform_interface: ^2.4.2
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
fake_async: ^1.3.3
camera_platform_interface: ^2.13.1
custom_lint: ^0.8.0
riverpod_lint: ^3.1.0
mocktail: ^1.0.4
# Test-only platform interface fakes (depend_on_referenced_packages).
path_provider_platform_interface: ^2.1.2
plugin_platform_interface: ^2.1.8
video_player_platform_interface: ^6.6.0
flutter:
config:
enable-swift-package-manager: false
uses-material-design: true
shaders:
- shaders/toast_island.frag
- shaders/onboarding_wordmark.frag
assets:
- assets/images/welcome-bee.svg
- assets/images/buzz-icon.png
- assets/images/shell-gradient.png
- assets/images/buzz-wordmark.png
# Generated by `just mobile-emoji-data` from the same emoji-mart dataset
# desktop uses. Do not hand-edit.
- assets/emoji/emoji-data.json
fonts:
- family: BuzzTabler
fonts:
- asset: assets/fonts/TablerIcons.ttf
- family: Inter
fonts:
- asset: assets/fonts/InterVariable.ttf
- asset: assets/fonts/InterVariable-Italic.ttf
style: italic
- family: GeistMono
fonts:
- asset: assets/fonts/GeistMono-Variable.ttf
- asset: assets/fonts/GeistMono-Italic-Variable.ttf
style: italic