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

Ideas to reduce the CPU impact of this middleware #21

Closed
rik opened this issue Apr 30, 2019 · 2 comments · Fixed by #22
Closed

Ideas to reduce the CPU impact of this middleware #21

rik opened this issue Apr 30, 2019 · 2 comments · Fixed by #22

Comments

@rik
Copy link
Contributor

rik commented Apr 30, 2019

I've had two ideas to save some CPU cycles but before implementing them, I wanted to check if you'd be interested in those changes:

  1. Change FEATURE_NAMES to a set to speed up if feature not in FEATURE_NAMES
  2. Generate and save the header in __init__. Django settings are not supposed to change so __call__ could write the string into the header. That means using django.test.signals.setting_changed for testing purposes though.
@adamchainz
Copy link
Owner

Yeah both seem sensible. I doubt you can spot this middleware in your benchmarking though! If you want to tackle them in a PR, please feel free.

rik added a commit to rik/django-feature-policy that referenced this issue May 7, 2019
- Use a set for faster membership test
- Generate the header once at boot time
- Disable the middleware if no header need to be added

fixes adamchainz#21
@rik rik closed this as completed May 7, 2019
@rik rik reopened this May 7, 2019
@rik
Copy link
Contributor Author

rik commented May 7, 2019

I haven't benchmarked it and you are probably right. It's just that I saw those opportunities to not work on every request.

adamchainz pushed a commit to rik/django-feature-policy that referenced this issue May 8, 2019
- Use a set for faster membership test
- Generate the header once at boot time
- Disable the middleware if no header need to be added

fixes adamchainz#21
adamchainz pushed a commit that referenced this issue May 8, 2019
- Use a set for faster membership test
- Generate the header once at boot time

fixes #21
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 a pull request may close this issue.

2 participants