feat: gather async deps concurrently with per-key deduplication#704
Closed
FRidh wants to merge 1 commit intoreagento:developfrom
Closed
feat: gather async deps concurrently with per-key deduplication#704FRidh wants to merge 1 commit intoreagento:developfrom
FRidh wants to merge 1 commit intoreagento:developfrom
Conversation
When resolving an async factory with 2+ async dependencies, the compiled getter now awaits them concurrently via asyncio.gather instead of sequentially. For N independent deps each taking T seconds, resolution takes max(T) instead of sum(T). No user-side changes are required. Concurrency safety for cached dependencies is handled via a _Pending Future sentinel in the cache dict: the first coroutine to resolve a dep places a sentinel; concurrent coroutines find it and await the embedded Future instead of duplicating work and registering duplicate exits. On failure the sentinel is removed from the cache and the exception is propagated to all waiters, so a subsequent retry resolves cleanly. This is a pure compile-time code generation change: the FactoryBuilder emits asyncio.gather calls and pending bookkeeping into the generated factory functions. The cache dict semantics, CompiledFactory protocol, Registry, and sync container are all unchanged. reagento#45
36ad7c0 to
4cc567a
Compare
|
Tishka17
reviewed
Apr 3, 2026
| container = make_async_container(IndependentDepsProvider()) | ||
| start = asyncio.get_running_loop().time() | ||
| result = await container.get(str) | ||
| elapsed = asyncio.get_running_loop().time() - start |
Member
There was a problem hiding this comment.
do not use time measurements in test assertions. Use events or barriers if you want to check concurrent execution
Author
|
Closing this POC, discussion in #45. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


When resolving an async factory with 2+ async dependencies, the compiled
getter now awaits them concurrently via asyncio.gather instead of
sequentially. For N independent deps each taking T seconds, resolution
takes max(T) instead of sum(T). No user-side changes are required.
Concurrency safety for cached dependencies is handled via a _Pending
Future sentinel in the cache dict: the first coroutine to resolve a dep
places a sentinel; concurrent coroutines find it and await the embedded
Future instead of duplicating work and registering duplicate exits.
On failure the sentinel is removed from the cache and the exception is
propagated to all waiters, so a subsequent retry resolves cleanly.
This is a pure compile-time code generation change: the FactoryBuilder
emits asyncio.gather calls and pending bookkeeping into the generated
factory functions. The cache dict semantics, CompiledFactory protocol,
Registry, and sync container are all unchanged.
#45