Skip to content

Lower startup memory usage by loading huge dictionaries from JSON files #114

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mparent61
Copy link

@mparent61 mparent61 commented Mar 27, 2025

Refactors initialization to load "ratio" and "gender_names" dictionary data from JSON instead of using giant static Python dictionaries.

When we originally added probablepeople to our Flask application, it increased our app's peak memory footprint by 600MB during startup, causing OOM errors in our deployment infrastructure. Following a suggestion from a related issue, and also taking inspiration from another fork, this eliminates the 600MB spike by loading the dictionary data from a JSON file.

I've taken a simple approach that attempts to minimize code changes, basically converting the two dictionary .py files to .json and loading at import-time. But certainly open to suggestions, as there are many ways to skin this cat.

@mparent61 mparent61 changed the title Lower startup memory by loading huge dictionary from file Lower startup memory by loading huge dictionaries from file Mar 27, 2025
@mparent61 mparent61 changed the title Lower startup memory by loading huge dictionaries from file Lower startup memory usage by loading huge dictionaries from JSON files Mar 27, 2025
@mparent61 mparent61 marked this pull request as ready for review March 27, 2025 19:56
@mparent61 mparent61 marked this pull request as draft March 28, 2025 15:52
@mparent61 mparent61 marked this pull request as ready for review April 2, 2025 18:17
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

Successfully merging this pull request may close these issues.

1 participant