feat: gather async deps concurrently with asyncio.gather + pending sentinel#705
Closed
FRidh wants to merge 1 commit intoreagento:developfrom
Closed
feat: gather async deps concurrently with asyncio.gather + pending sentinel#705FRidh wants to merge 1 commit intoreagento:developfrom
FRidh wants to merge 1 commit intoreagento:developfrom
Conversation
c273482 to
c3c4044
Compare
…ntinel 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. This is implemented as a compile-time code generation change: the compiled factory function is generated with asyncio.gather instead of sequential inline awaits. The cache dict semantics and CompiledFactory protocol are unchanged, and the sync container is unaffected. Diamond patterns (A→C, B→C) are handled via a _Pending Future sentinel: the first coroutine to resolve a cached dep places a sentinel in the cache; concurrent coroutines await it instead of duplicating work and registering duplicate exits. Uncached (cache=False) shared deps are also safe to gather since each branch creates its own independent instance. reagento#45
c3c4044 to
3b0f09a
Compare
|
Member
|
I am a bit worried because you made commits almost simultaneously on two PRs. Did you write this code? |
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.
This is implemented as a compile-time code generation change: the
compiled factory function is generated with asyncio.gather instead of
sequential inline awaits. The cache dict semantics and CompiledFactory
protocol are unchanged, and the sync container is unaffected.
Diamond patterns (A→C, B→C) are handled via a _Pending Future sentinel:
the first coroutine to resolve a cached dep places a sentinel in the
cache; concurrent coroutines await it instead of duplicating work and
registering duplicate exits. Uncached (cache=False) shared deps are also
safe to gather since each branch creates its own independent instance.
#45