Skip to content

Fixed #36439 -- Optimized acheck_password by using sync_to_async on verify_password. #19611

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

Merged

Conversation

roelzkie15
Copy link
Contributor

@roelzkie15 roelzkie15 commented Jun 30, 2025

Trac ticket number

ticket-36439

Branch description

Conducted several experiments/benchmarks on the performance of the acheck_password that blocks asyncio's event-loop, which is causing a performance bottleneck. Adding a ThreadPoolExecutor significantly improved the performance gap compared to the test without using it.

Also, introduced the CHECK_PASSWORD_EXECUTOR_MAX_WORKERS for allowing developers to provide a configurable setting for the ThreadPoolExecutor instance. See the updated document on this PR.

EDIT:

Please check the new experiments/benchmarks on the performance of the acheck_password that blocks asyncio's event-loop, which is causing a performance bottleneck by using the sync_to_async on the verify_password.

EDIT 2:

Added a new benchmark via django-asv here: django/django-asv#94


Note: The idea was not mine but by Robert Aistleitner who proposed it which was later on picked up by me since it has no owner for 4 weeks.

This PR targets a patch for v5.2 as mentioned in the ticket.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from 3750296 to 1bb5279 Compare July 1, 2025 10:35
@roelzkie15 roelzkie15 changed the title Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a ThreadPoolExecutor Perf #36439: Optimize acheck_password CPU heavy internal hashing process by using a ThreadPoolExecutor Jul 1, 2025
@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from b984047 to c9eec27 Compare July 1, 2025 17:01
@roelzkie15 roelzkie15 marked this pull request as draft July 1, 2025 18:14
@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from c9eec27 to d1a1ef1 Compare July 1, 2025 18:16
@roelzkie15 roelzkie15 marked this pull request as ready for review July 1, 2025 18:17
@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from d1a1ef1 to 50a6d87 Compare July 1, 2025 18:19
@roelzkie15
Copy link
Contributor Author

Based on the ticket, a test may not be needed for this patch.

@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from 50a6d87 to b5354b5 Compare July 5, 2025 15:57
@roelzkie15 roelzkie15 changed the title Perf #36439: Optimize acheck_password CPU heavy internal hashing process by using a ThreadPoolExecutor Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a ThreadPoolExecutor Jul 5, 2025
@roelzkie15 roelzkie15 marked this pull request as draft July 16, 2025 07:07
@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from b5354b5 to c591c40 Compare July 19, 2025 13:15
@roelzkie15 roelzkie15 changed the title Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a ThreadPoolExecutor Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a sync Jul 19, 2025
@roelzkie15 roelzkie15 changed the title Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a sync Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a sync_to_async on verify_password. Jul 19, 2025
@roelzkie15 roelzkie15 marked this pull request as ready for review July 19, 2025 13:22
@roelzkie15 roelzkie15 requested a review from sarahboyce July 19, 2025 13:27
@sarahboyce
Copy link
Contributor

Thank you @roelzkie15 👍
I've read your comment, we just need to have other folks verify the benchmarks. I wasn't able to replicate so some options are:

  • write a benchmark within django-asv
  • publish a runnable script (or repo) for other folks to run the benchmarks

@roelzkie15
Copy link
Contributor Author

Thank you @roelzkie15 👍 I've read your comment, we just need to have other folks verify the benchmarks. I wasn't able to replicate so some options are:

  • write a benchmark within django-asv
  • publish a runnable script (or repo) for other folks to run the benchmarks

I have created a PR on django-asv to add the benchmarks here: django/django-asv#94. Instructions are also included for other folks to test the benchmark.

If something I need to improve on that benchmark PR, don't hesitate to let me know. 🙏🏼

roelzkie15 added a commit to roelzkie15/django-asv that referenced this pull request Jul 24, 2025
@roelzkie15 roelzkie15 force-pushed the fix-36439-auth-hashing-performance branch from ce3e0e7 to f8a010f Compare July 24, 2025 16:46
@sarahboyce sarahboyce force-pushed the fix-36439-auth-hashing-performance branch from f8a010f to beb9f80 Compare July 30, 2025 13:20
@sarahboyce sarahboyce changed the title Fixed #36439: Optimize acheck_password CPU heavy internal hashing process by using a sync_to_async on verify_password. Fixed 36439 -- Optimized acheck_password by using sync_to_async on verify_password. Jul 30, 2025
@github-actions github-actions bot added the no ticket Based on PR title, no linked Trac ticket label Jul 30, 2025
Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR to django-asv, I was able to replicate the performance improvement via the benchmarks 👍

@sarahboyce sarahboyce force-pushed the fix-36439-auth-hashing-performance branch from beb9f80 to 570d20a Compare July 30, 2025 13:22
@sarahboyce sarahboyce changed the title Fixed 36439 -- Optimized acheck_password by using sync_to_async on verify_password. Fixed #36439 -- Optimized acheck_password by using sync_to_async on verify_password. Jul 30, 2025
@github-actions github-actions bot removed the no ticket Based on PR title, no linked Trac ticket label Jul 30, 2025
@sarahboyce sarahboyce merged commit 748ca0a into django:main Jul 31, 2025
34 checks passed
@roelzkie15 roelzkie15 deleted the fix-36439-auth-hashing-performance branch July 31, 2025 14:24
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy