Skip to content

Batch Kyo requests across composed relations - #400

Open
yoohaemin wants to merge 7 commits into
masterfrom
fix/kyo-composed-batching
Open

yoohaemin wants to merge 7 commits into
masterfrom
fix/kyo-composed-batching

Conversation

@yoohaemin

@yoohaemin yoohaemin commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Kyo datasource implementations handled Batch separately for each relation invocation. Zipped branches and overlapping derived groups could not share requests.

Build a reusable query plan with structured datasource/key requests. foreach combines independent plans; native grouped sources deduplicate keys and reconstruct result positions. Dependent stages resume after inputs arrive, with trampolined composition and balanced traversal.

startingFrom / startingFromMany preserve handled Kyo execution. New toBatch / toBatchMany leave Batch to the caller, allowing separate traversals to share an outer handler. Register a KyoBatchSource once and pass it to datasource constructors to share its native toBatch handle too. Existing callback signatures remain supported. No persistent cache or concurrent datasource execution guarantee is added.

Low-level reification now returns a plan with .toBatch, rather than a direct effect. Ordinary custom effects use KyoBatchQuery.lift and execute per occurrence. See kyo-batch/README.md for migration and native interoperability.

The optional ZQuery interpretation is on feat/kyo-zquery (no new PR opened), using the same proofs and shared sources without duplicate callbacks. This PR has no ZQuery runtime dependency.

Validation: 21 core regressions pass on JVM; Scala.js composition and collection suites pass separately. Coverage includes native source sharing, source isolation, duplicate/empty inputs, nested groups, dependent stages, typed failures, ordinary lifted effects, reruns, 4,096-input traversal and 100,000-deep composition. Changed Scala sources are formatted.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 05:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Long public query composition chains can overflow the stack during execution.

1 open issue
What changed in this PR

Introduces reusable Kyo query plans to batch requests across composed relations while preserving output positions.

Changes:

  • Groups independent requests by dependency stage.
  • Migrates interpreter execution to query plans and documents compatibility.
  • Adds batching regression tests and test dependencies.
File Description
kyo-batch/​src/​test/​scala/​decrel/​reify/​KyoBatchSpec.scala Tests batching, ordering, composition, and plan reuse.
kyo-batch/​src/​main/​scala/​decrel/​reify/​KyoBatchQuery.scala Implements query composition and staged execution.
kyo-batch/​src/​main/​scala/​decrel/​reify/​kyoBatch.scala Integrates query plans into the interpreter.
kyo-batch/​README.md Documents batching semantics and migration.
build.sbt Adds Kyo module test dependencies.

Review effort: Balanced

@yoohaemin
yoohaemin force-pushed the refactor/typed-interpreter-zip branch from afadfe5 to 953aadd Compare November 2, 2026 13:00
@yoohaemin
yoohaemin force-pushed the fix/kyo-composed-batching branch from 3d27c17 to 800b44b Compare November 2, 2026 13:00
@yoohaemin
yoohaemin force-pushed the fix/kyo-composed-batching branch from 800b44b to ec1ecf0 Compare November 2, 2026 13:34
Base automatically changed from refactor/typed-interpreter-zip to master November 2, 2026 13:48
@yoohaemin
yoohaemin force-pushed the fix/kyo-composed-batching branch from ec1ecf0 to d056c32 Compare November 2, 2026 13:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Sequential source submission can miss shared batching and repeat callbacks, while suspending flatMap chains incur quadratic wrapper rebuilding.

2 open issues
1 resolved since last review

Review effort: Balanced

type State = pending.State
val initial = pending.initial
val requests = pending.requests
def resume(state: State): KyoBatchQuery[S, B] = defer(pending.resume(state)).flatMap(f)
}
val groups = fetches.groupBy(_.source).toVector
Kyo
.foreach(groups) { case (source, requests) =>

This branch has not been deployed

No deployments
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