perf(sdk): batch invoke-path lookups with DataLoader semantics - #1244
Closed
RhysSullivan wants to merge 1 commit into
Closed
perf(sdk): batch invoke-path lookups with DataLoader semantics#1244RhysSullivan wants to merge 1 commit into
RhysSullivan wants to merge 1 commit into
Conversation
Concurrent execute calls in the same microtask window now share one query per table (tool, connection, integration) plus one policy rule-set snapshot instead of four point queries per call, killing the N+1 pattern under code-mode fan-out and parallel MCP tool calls. - invoke-batching.ts: Request types + resolvers keyed by plain data; batch loaders serve mixed tuples with a single OR-of-tuples query and dedupe equal keys before hitting storage. No cross-batch caching, so read-your-writes behavior is unchanged. - Transactional callers bypass the batch window (a shared batch fiber would read through the wrong activeFumaDbRef) and keep exact per-transaction semantics. - Proof test counts real queries through a spying FumaDb wrapper: 25 concurrent executes touch each table at most twice; sequential calls still issue the same per-call point reads as before.
Contributor
Cloudflare previewTorn down — the PR is closed. |
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.
What
Concurrent
execute()calls in the same microtask window now share one storage query per table (tool, connection, integration) plus one policy-rule-set snapshot, instead of four point queries per call. Naive fan-out code —Promise.allover tool calls, code-mode loops, parallel MCP tool calls — no longer produces N+1 query storms.Built on Effect
Request/RequestResolver: each hot lookup on the invoke path is a request keyed by plain data, and a resolver serves the collected batch with a single OR-of-tuples query (keys deduped before hitting storage).Behavior preserved
fuma.transactionthe handle rides onactiveFumaDbRef, so a shared batch would read through the wrong connection. Transactional reads run the loader directly with exact isolation.Proof
invoke-batching.test.tscounts real queries through a spying FumaDb wrapper:ToolNotFoundError; peers succeed.Gates
format:check,lint,typecheck, and the full test suite (36 packages) all pass.