Title: Very slow performance with firebase_admin.auth.list_users().iterate_all() · Issue #571 · firebase/firebase-admin-python · GitHub
Open Graph Title: Very slow performance with firebase_admin.auth.list_users().iterate_all() · Issue #571 · firebase/firebase-admin-python
X Title: Very slow performance with firebase_admin.auth.list_users().iterate_all() · Issue #571 · firebase/firebase-admin-python
Description: Operating System version: n/a Firebase SDK version: firebase-admin==5.0.2 Firebase Product: auth, user management Python version: 3.8 Pip version: n/a [REQUIRED] Step 3: Describe the problem When fetching all user accounts using the fire...
Open Graph Description: Operating System version: n/a Firebase SDK version: firebase-admin==5.0.2 Firebase Product: auth, user management Python version: 3.8 Pip version: n/a [REQUIRED] Step 3: Describe the problem When f...
X Description: Operating System version: n/a Firebase SDK version: firebase-admin==5.0.2 Firebase Product: auth, user management Python version: 3.8 Pip version: n/a [REQUIRED] Step 3: Describe the problem When f...
Opengraph URL: https://github.com/firebase/firebase-admin-python/issues/571
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Very slow performance with firebase_admin.auth.list_users().iterate_all()","articleBody":" * Operating System version: n/a\r\n * Firebase SDK version: firebase-admin==5.0.2 \r\n * Firebase Product: auth, user management\r\n * Python version: 3.8\r\n * Pip version: n/a\r\n\r\n### [REQUIRED] Step 3: Describe the problem\r\n\r\nWhen fetching all user accounts using the firebase_admin.auth.list_users().iterate_all() helper, performance is very poor, taking about 5 seconds to fetch 1000 users.\r\n\r\nI have a project which has several million users. There is a scheduled task that fetches all the users for processing, but the task takes way too long and runs into problems with App Engine request timeouts.\r\n\r\n#### Steps to reproduce:\r\n\r\nHere is an App Engine standard + Python 3.8 project which has 2 routes to show the difference between iterating through all users using the iterate all helper, versus fetching each page directly:\r\n\r\nhttps://gist.github.com/davidwtbuxton/c6bbdc1e93f686cae931d1e38b5bd555\r\n\r\nThe code logs a message for every 1000 users. In my testing it takes about 5 seconds for every 1000 users on the slow path (using iterate_all) and about 1 second for every 1000 users on the fast path (not using iterate_all).\r\n\r\n\r\n#### Relevant Code:\r\n\r\n\r\nI've got a WIP patch here https://github.com/davidwtbuxton/firebase-admin-python/commit/20991aafcb007a9d4c7fc4bd8589ebff5de1ab16\r\n\r\nI need to test that WIP patch some more, but would this be useful? Suggestions for improving the patch?\r\n\r\nI think the cause of the poor performance is the [PageIterator class][1] and how next() is implemented. In the next() method, the code evaluates `self.items` 3 times. For the [_UserIterator class][2] the items list is actually a computed property, which accesses [ListUsersPage.users][3], which is also a computed property that builds a new list of user records.\r\n\r\nSo for each user in the list of users, the iterator ends up triggering a list of all users in the current page to be constructed 3 times, just to access 1 user. When a page has 1000 users, this ends up being much slower (1000 x 3) than the ideal case of constructing the list just 1 time for each page.\r\n\r\n[1]: https://github.com/firebase/firebase-admin-python/blob/01db7eb8da6094e09fc0311930718deec5ccd4ad/firebase_admin/_auth_utils.py#L35\r\n[2]: https://github.com/firebase/firebase-admin-python/blob/01db7eb8da6094e09fc0311930718deec5ccd4ad/firebase_admin/_user_mgt.py#L845\r\n[3]: https://github.com/firebase/firebase-admin-python/blob/01db7eb8da6094e09fc0311930718deec5ccd4ad/firebase_admin/_user_mgt.py#L357","author":{"url":"https://github.com/davidwtbuxton","@type":"Person","name":"davidwtbuxton"},"datePublished":"2021-09-08T11:04:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/571/firebase-admin-python/issues/571"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a3564682-9ed1-d2a2-7f92-70bfd200e9e0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F70:201A54:148B6C2:1A95AB2:69924A8B |
| html-safe-nonce | 23d8be8fa080841fb87a9590f6faf6f53d52c98ce27902a6fcc2ac4bd2252bc7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjcwOjIwMUE1NDoxNDhCNkMyOjFBOTVBQjI6Njk5MjRBOEIiLCJ2aXNpdG9yX2lkIjoiMjUyNjg2MTg1NjIzODM1NzEzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2350eb6a50fd3ed5d1f72bfa3ac5f7fce5cf6d7cea7a94d138baa20c02541048 |
| hovercard-subject-tag | issue:991012838 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/firebase/firebase-admin-python/571/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0f12484a300256275acc6df880cdff51d994824c78681f9462e28c3240780534/firebase/firebase-admin-python/issues/571 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0f12484a300256275acc6df880cdff51d994824c78681f9462e28c3240780534/firebase/firebase-admin-python/issues/571 |
| og:image:alt | Operating System version: n/a Firebase SDK version: firebase-admin==5.0.2 Firebase Product: auth, user management Python version: 3.8 Pip version: n/a [REQUIRED] Step 3: Describe the problem When f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | davidwtbuxton |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/firebase/firebase-admin-python git https://github.com/firebase/firebase-admin-python.git |
| octolytics-dimension-user_id | 1335026 |
| octolytics-dimension-user_login | firebase |
| octolytics-dimension-repository_id | 84979152 |
| octolytics-dimension-repository_nwo | firebase/firebase-admin-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 84979152 |
| octolytics-dimension-repository_network_root_nwo | firebase/firebase-admin-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width