Skip to content

Conversation

jonesnc
Copy link

@jonesnc jonesnc commented Jul 11, 2025

Changes

Lazily import firebase_admin and its modules because we've found it's one of the slower modules to import in our Django projects. For type annotations, the firebase_admin is only imported after checking typing.TYPE_CHECKING.

Please let me know if you have any suggestions or feedback on this, I'd be happy to implement them.

Thanks for this package, I think it's great!

Tests

Test session starts (platform: linux, Python 3.10.12, pytest 8.2.2, pytest-sugar 1.0.0)
django: version: 4.2.19, settings: tests.settings.default (from ini)
rootdir: /home/nathanjones/Projects/fcm-django
configfile: pyproject.toml
plugins: sugar-1.0.0, anyio-3.6.2, mock-3.14.1, django-4.11.1, asyncio-0.14.0, Faker-15.3.4, typeguard-2.13.3
collected 16 items

 tests/test_admin.py ✓✓                                                                                                                                                                                                                      12% █▍
 tests/test_api_rest_framework.py ✓✓✓                                                                                                                                                                                                        31% ███▎
 tests/test_api_tastypie.py ✓                                                                                                                                                                                                                38% ███▊
 tests/test_models.py ✓✓✓✓✓✓✓✓✓✓                                                                                                                                                                                                            100% ██████████

Results (3.49s):
      16 passed

@jonesnc
Copy link
Author

jonesnc commented Jul 14, 2025

@xtrinch I just pushed edfc18e (#279), hopefully that fixes the formatting errors.

@jonesnc
Copy link
Author

jonesnc commented Jul 14, 2025

@xtrinch Sorry, I missed one error. I just fixed that one as well.

@jonesnc
Copy link
Author

jonesnc commented Jul 14, 2025

@xtrinch I'm not sure how to fix the 3.7 action. onnx/tensorflow-onnx#2376 suggests limits 3.7 to ubuntu 22.04, maybe that's the solution?

Let me know if there's anything I can do to help.

@xtrinch
Copy link
Owner

xtrinch commented Jul 15, 2025

Python 3.7 has reached its end of life, I believe we can safely remove it.
Other than that, I'd like to hear some more opinions from people on this PR, whether this is something that more people would like to see happen.
I'd also like to hear what magnitude of a slowdown you are experiencing with eagerly importing firebase_admin.

@jonesnc
Copy link
Author

jonesnc commented Jul 15, 2025

I'd also like to hear what magnitude of a slowdown you are experiencing with eagerly importing firebase_admin.

According to python -X importtime manage.py runserver --noreload, it's adding about 120ms to our total startup time. In my Django project, that's ~6% of the current total Django start/restart time when running makemigrations or runserver, for example.

In isolation, that probably doesn't sound like a lot, but I work on a project with a lot of different dependencies, so I'm always looking for ways to improve the import/setup speed of those dependencies. We tend to accumulate a lot of performance benefit by optimizing many of our different imports, so every little bit counts to the overall goal of improving django start time.

For example, if we can improve the import time of 5 different dependencies that each take about 100ms to import and firebase_admin is one of those in this example, that's a total of 500ms startup improvement, which means our dev experience is 500ms faster. That's my intent with this change.

Thanks for your time and consideration.

@ahmedbilal
Copy link

@jonesnc This latest release 2.3.1 bump up the ceiling for firebase_admin constraint allowing firebase_admin 7 as dependency which removed the dependency on google-api-python-client thus significantly reducing the overall footprint (memory + size) of this package. Can you run your profiling again and see whether you need these changes? Thanks.

@jonesnc
Copy link
Author

jonesnc commented Jul 29, 2025

It looks like my project will take some work to update to firebase_admin version 7, so I can't provide any importtime benchmark results at this time. I'll work on this and get back with you.

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.

3 participants