Use AnyIO with `fast_acquire` synchronization by MarkusSintonen · Pull Request #953 · encode/httpcore · GitHub
Skip to content

Use AnyIO with fast_acquire synchronization #953

Merged
graingert merged 3 commits into
encode:masterfrom
MarkusSintonen:anyio-fast-acquire
Mar 27, 2025
Merged

Use AnyIO with fast_acquire synchronization #953
graingert merged 3 commits into
encode:masterfrom
MarkusSintonen:anyio-fast-acquire

Conversation

@MarkusSintonen

Copy link
Copy Markdown
Contributor

Summary

Related to agronholm/anyio#761 and #922 (comment)

This uses AnyIOs fast_acquire-mode in its synchronization primitives (instead of replacing AnyIO with vanilla asyncio). Which gives a big performance boost (see above comment lint).

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@graingert

Copy link
Copy Markdown
Contributor

@graingert graingert merged commit 973cbdd into encode:master Mar 27, 2025
@lovelydinosaur

Copy link
Copy Markdown
Contributor

@graingert No. Please don't do that on this PR.

This was my latest comment regarding this... #922 (comment)

Here's a comment that'd make me wary of jumping onto fast_acquire=True... agronholm/anyio#761 (review)

@graingert

Copy link
Copy Markdown
Contributor

Happy for a revert, does #927 remove a lock on the async code path and therefore make this PR redundant?

@lovelydinosaur

Copy link
Copy Markdown
Contributor

I'm not talking about #927 or directing my attention there at the moment.

@lovelydinosaur

Copy link
Copy Markdown
Contributor

Revert PR at #1002.

@Nivyaal-zenity

Copy link
Copy Markdown

When will the tag related to this change here and on httpx will be relaesed?

lovelydinosaur added a commit that referenced this pull request Mar 31, 2025
@ofek

ofek commented Apr 19, 2025

Copy link
Copy Markdown

I'm confused about what happened here; what was the technical issue?

@zanieb

zanieb commented Apr 19, 2025

Copy link
Copy Markdown
Contributor

@ofek

ofek commented Apr 19, 2025

Copy link
Copy Markdown

Ah I missed the second comment, thanks! I don't do enough async in Python to know what that means but I'll take a deeper dive eventually because such performance improvements always intrigue me.

@agronholm

agronholm commented Apr 26, 2025

Copy link
Copy Markdown
Contributor

@graingert No. Please don't do that on this PR.

This was my latest comment regarding this... #922 (comment)

Here's a comment that'd make me wary of jumping onto fast_acquire=True... agronholm/anyio#761 (review)

Can you explain this to me, as it didn't make a lick of sense to me? Was this about fast_acquire=True skipping the checkpoint? asyncio.Lock never had that checkpoint to begin with, so what do you suppose is gained by reverting the commit?

@lovelydinosaur

Copy link
Copy Markdown
Contributor

what do you suppose is gained by reverting the commit?

@agronholm So. The priority at the time was bumping a release from 1.0.7 to 1.0.8 in order to resolve #1005.

Mixing in other concerns introduces risk, rather than just prioritising the necessary fix for Python 3.14.0a6.


Also I've been doing some background work on a significantly simplified implementation. I've got a connection pool approach that's smaller, more readable, and easier to reason about. It also happens to result in faster & more stable response characteristics under load. (significant improvement vs. current httpx, marginal improvement vs. aiohttpx)

I'm not ready to share the work publicly yet, tho will update shortly.

@agronholm

Copy link
Copy Markdown
Contributor

what do you suppose is gained by reverting the commit?

@agronholm So. The priority at the time was bumping a release from 1.0.7 to 1.0.8 in order to resolve #1005.

Mixing in other concerns introduces risk, rather than just prioritising the necessary fix for Python 3.14.0a6.

Also I've been doing some background work on a significantly simplified implementation. I've got a connection pool approach that's smaller, more readable, and easier to reason about. It also happens to result in faster & more stable response characteristics under load. (significant improvement vs. current httpx, marginal improvement vs. aiohttpx)

I'm not ready to share the work publicly yet, tho will update shortly.

OK, thanks for the quick response. I was previously left with the impression that you had reservations about fast_acquire, but perhaps I misunderstood.

@lovelydinosaur

Copy link
Copy Markdown
Contributor

I was previously left with the impression that you had reservations about fast_acquire, but perhaps I misunderstood.

I don't really know enough about fast_acquire to take an informed stance on that.

(Incidentally, thanks so much for your work on anyio, and helping bring structured concurrency patterns to Python's asyncio.)

@agronholm

Copy link
Copy Markdown
Contributor

mbeijen added a commit to mbeijen/httpx2 that referenced this pull request May 19, 2026
Reinstates encode/httpcore#953 which was reverted in encode/httpcore#1002
for process reasons, not technical ones. fast_acquire=True skips an
unnecessary event loop yield on uncontended lock acquires, eliminating
two round-trips per request through the connection pool.

Requires anyio >= 4.5.0 (bumped in pyproject.toml).
mbeijen added a commit to mbeijen/httpx2 that referenced this pull request May 20, 2026
Reinstates encode/httpcore#953 which was reverted in encode/httpcore#1002
for process reasons, not technical ones. fast_acquire=True skips an
unnecessary event loop yield on uncontended lock acquires, eliminating
two round-trips per request through the connection pool.

Requires anyio >= 4.5.0 (bumped in pyproject.toml).
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.

7 participants