-
Notifications
You must be signed in to change notification settings - Fork 140
Adding thousands of views to a client is extremely slow #1286
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
Comments
Hi, I suggest taking a look at this example (and if you really want to go with that take a look at this project, it's still in a WIP phase but makes everything easier, you can also ask questions in the discord channel of that project), views don't scale well, above all if we're talking about persistent views. The real issue here is that you need to add a new persistent view every time your bot creates a poll, this way of doing it is not sustainable from the limited resource perspective (too much ram wasted just to store views). The links above bring you to a much more nice and clean way of doing that. |
Agree with @Snipy7374 here; at that scale, the sustainable solution would likely be to start using listeners instead of individual views. |
(Also, discord has native polls now, why not use them?) |
@Enegg My poll bot Paul has many more features than Discord's native polls.
|
Summary
Registering thousands of persistent views on startup takes O(n^2) time because
ViewStore.__verify_integrity
gets called each time one is added, and that is O(n).Reproduction Steps
My bot is a polling bot. On startup I load all the polls from the database, then register a persistent view for each poll, so the bot can continue to respond to interactions on old polls.
Minimal Reproducible Code
Expected Results
I expect
Client.add_view
to run in O(1) time, causing my bot to load in linear time.Actual Results
My bot has grown to have about 22K polls. Now it takes about 30 minutes to start up, though I notice that at the beginning it loads polls quite fast, but as it progresses it gets slower and slower.
This is because
Client.add_view
runs in O(n) time, since each time it callsViewStore.__verify_integrity
, which iterates over all previously added views.Intents
None
System Information
Checklist
Additional Context
I think a possible solution would be to have a method
Client.bulk_add_views
which would propagate to a new methodViewStore.add_views
which would only callViewStore.__verify_integrity
once.The text was updated successfully, but these errors were encountered: