Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications slow to load #621

Open
graue opened this issue Aug 11, 2024 · 2 comments
Open

Notifications slow to load #621

graue opened this issue Aug 11, 2024 · 2 comments

Comments

@graue
Copy link
Contributor

graue commented Aug 11, 2024

I'm finding notifications very slow to load (first time in a session) or to refresh.

Looking into it, the request to /api/v1/notifications?limit=80&exclude_types[]=follow_request averages about 3 seconds on my primary instance, and about 1 second on my alt on a different instance. (It's returning about 500kB of data, ~180kB of which is copies of my own profile attached to every reblog and favourite notification.)

Maybe this is a server tuning issue or an inefficient Mastodon API design issue, and maybe server-side batching of notifications will make this better, but... I also wonder why Phanpy requests 80 notifications every time I open the notifications tab. Couldn't it only request the new ones? Also, could the initial set of notifications be requested eagerly when I open Phanpy (Mastodon web does this, so notifs feel faster), and new ones requested in the background as they become available through the streaming API?

  • Which site: phanpy.social
  • Which site version: 2024.08.08.dabb480
  • Which instance: mainly carfree.city

To Reproduce

  1. Open Phanpy
  2. Click on profile pic with blue circle in top left
  3. Click on Notifications
  4. Wait a long time

Expected behavior
Notifications show up pretty fast or immediately

Desktop (please complete the following information):

  • OS: Linux
  • Browser: Firefox
  • Version: 129
@cheeaun
Copy link
Owner

cheeaun commented Aug 11, 2024

I personally would see this as a backend issue, but first, some notes for context:

  • 80 is used because that's the max Mastodon allows. It was bumped up at some point on Mastodon's side to enable clients to request more, so I assumed the server could handle it 🫣 (Phanpy is probably not the only client setting it to 80) - This change was done on Phanpy 3 months ago, from 30 to 80 025a542
  • 80 is used so that client-side notifications grouping works better. For 1st "page" load, it'll always be 80 instead of prepending "newer" notifications because the grouping is re-rendered (everything is regrouped again) instead of "cut off" at the top. The grouping will only "cut off" for subsequent "next" paginated responses.
  • This could probably be solved if Phanpy stores individual notifications in a local DB (like how most native apps work), so there's no "wasted" API calls, but I haven't look into it yet.

If this proves to be an issue for many servers, perhaps we can lower the limit to a reasonable number?

@graue
Copy link
Contributor Author

graue commented Aug 11, 2024

Thanks for the context on why it works as it does. I gather then that the way Phanpy is storing the notifications on the client side now, they're pre-grouped? I like the idea of storing individual notifications in a way that would allow for new ones to be added in piecemeal.

Maybe in that case it would also be practical to load notifications eagerly, before the "page" is viewed? On the faster of the two instances I have accounts on, when Mastodon web requests 40 notifications, it still takes between 500 ms and 1 sec, so it seems like it's going to be a perceptible delay regardless of the limit. Is this much faster on the server(s) you use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants