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

Memory usage awareness: recommend late import #72

Open
sparrowt opened this issue Oct 20, 2023 · 0 comments
Open

Memory usage awareness: recommend late import #72

sparrowt opened this issue Oct 20, 2023 · 0 comments

Comments

@sparrowt
Copy link

sparrowt commented Oct 20, 2023

While profiling memory usage I noticed that importing zxcvbn was causing ~12mb of memory allocation:
image

This is not necessarily surprising but I thought I'd mention it here in case there was any obvious way to reduce it.

According to the profiling there was:

  • 5 MB from the top level importing of site-packages/zxcvbn/frequency_lists.py:4
  • 7 MB from build_ranked_dict.<locals>.<dictcomp> while importing site-packages/zxcvbn/matching.py:10
    • matching.py imports frequency_lists and processes them into RANKED_DICTIONARIES which causes the extra usage

I'm not necessarily suggesting that the behaviour of this package be changed, though I guess it would be possible to make the import very cheap and lazily do all the above effort only the first time it is required.

In the mean time though, I could easily get an equivalent benefit by moving my import of zxcvbn to happen only inside the request handler which needs it, so that most of the python processes handling requests didn't need to bother, unless they received a request involving a user attempting to set a password.

@sparrowt sparrowt changed the title Awareness about memory consumption Memory usage awareness: recommend late import Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant