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

Very poor performance of Pagination.{pages,iter_pages} #622

Closed
wodim opened this issue May 16, 2018 · 2 comments · Fixed by #1087
Closed

Very poor performance of Pagination.{pages,iter_pages} #622

wodim opened this issue May 16, 2018 · 2 comments · Fixed by #1087
Milestone

Comments

@wodim
Copy link

wodim commented May 16, 2018

The performance of those two methods is really really bad when you have thousands of pages. In my case, with 100k pages, painting the paginator takes over 300 ms.

Pagination.iter_pages is slow by itself. Pagination.pages is not that slow but it's called once for every page from Pagination.iter_pages when you consume the iterator, and calling it 100k times really adds up. Python is a very slow language and calling the same method so many times is undesirable even if the method seems simple.

The low-hanging fruit here is caching the result of Pagination.pages. That fixes more than half of the problem (only the call to Pagination.iter_pages remains). I did so with this subclass, which might be helpful to someone. (I'm far from an expert in Python, so this may hurt your eyes)

class MyPagination(Pagination):

    def __init__(self, query, page, per_page, total, items):
        super().__init__(query, page, per_page, total, items)
        self._pages = super().pages

    @property
    def pages(self):
        return self._pages

But of course a better solution is desirable.

@dourvaris
Copy link

#393

@rsyring rsyring added this to the 3.x milestone Mar 9, 2019
@davidism davidism modified the milestones: 3.x, 3.0 Sep 18, 2022
@davidism
Copy link
Member

fixed in #1087

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

4 participants