Skip to content

Reduce inference and I/O overhead with native string output - #138

Open
arthurianresolve wants to merge 137 commits into
krypticmouse:mainfrom
arthurianresolve:fix-inference-io-performance
Open

arthurianresolve wants to merge 137 commits into
krypticmouse:mainfrom
arthurianresolve:fix-inference-io-performance

Conversation

@arthurianresolve

@arthurianresolve arthurianresolve commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary of Fix

Stacked on #137. Merge #137 and its parent PRs before this PR.

  • Skip history-record construction and prompt serialization when all global, LM and enclosing caller history stores have zero capacity. Preserve enabled caller history and independent trace capture.
  • Avoid constructing unused provider request messages on response-cache hits, and copy only the cached response. Retain the full-entry inspection API.
  • Remove redundant schema text from primitive native-output prompts while preserving task instructions, field descriptions and format diagnostics. Complex outputs retain their schema text.
  • Format primitive native-schema demonstrations as the compact JSON requested by their system prompt. Preserve output aliases and existing JSON-mode, complex-schema and scalar formatting.
  • Add LM::with_scalar_output_schema(true) for verified endpoints that accept root JSON strings. Tool-free signatures with one string output can omit the generated object wrapper while preserving typed results, aliases, coercion and constraints.
  • Keep numeric, boolean, multiple and complex outputs and tool agents on their existing object-schema paths.
  • Add --scalar-output to the Ollama example, alongside offline --inspect-only support.
  • Add reproducible benchmarks, build records, hashes, raw samples and a report covering live inference, cached calls and offline framework overhead.

Fixes #22

Why

Disabling history retention previously left the work of constructing records and serializing prompts in every call. Cache hits also prepared provider request structures that were discarded.

For a single string output, generating an object wrapper adds model output tokens even though the field name is already known. On a verified endpoint, requesting a JSON string lets the adapter restore that field name before running the existing coercion and validation stages.

The scalar capability is disabled by default. Custom endpoints also require with_custom_output_schema(true). Numeric scalar experiments failed live arithmetic checks, so production eligibility is restricted to string outputs; the final object fallbacks pass those checks.

Related work

Testing

  • Follow-up native-schema correction: all 29 focused release tests passed without default features (seven schema/typed-chat checks and 22 interpreter checks). Coverage includes compact aliased demonstrations, descriptive nested outputs and the uncached retry path. The cache-specific retry regression is now gated on its feature; it also passes separately with caching enabled on the integrated profiling branch.

  • Final integrated cache-enabled release checks: 61 tests passed using --no-default-features --features cache (three live tests excluded from this offline run). This covers invocation history, persistent storage, tool-loop limits, native/scalar output and trace/history parity.

  • The original performance measurements remain tied to the frozen revisions in their retained reports. The new integration commits have functional regression coverage; the earlier speedup ratios have not been remeasured on this head.

  • Integrate typed tool-field metadata and persistent storage with the scalar response path. A storage scope records calls even when all bounded history capacities are zero.

  • Focused regression suites: 189 passed with default features and 169 passed without defaults. Three live tests were ignored in each offline run.

  • Explicit live validation: all nine example workflows and four scalar/fallback cases passed against Ollama 0.40.16 with llama3.2 in WSL Ubuntu 24.04.

  • Coverage includes aliases, demos, constraints, conversations, config copies, history, cache separation, JSONL trace round trips, strict replay and object fallbacks.

  • Offline scalar prompt preview passed with an unreachable endpoint.

  • git diff --check — passed. The complete workspace test suite was not run.

Controlled release measurements against DSPy 3.2.1:

Mode Measured speedup
Live inference, response cache disabled 2.61×
Warm response-cache calls 59.72×
Offline typed calls with mock providers 36.99×

Each mode includes eight samples per program in balanced order, with answer and HTTP-count checks. Attempts affected by detected Cargo/rustc activity were rejected and retained.

These results apply to the documented warm QA workload. The live gain requires the single-string opt-in; cold starts and other models or signatures have no general 2× guarantee. Compared with the pre-scalar DSRs baseline, live calls were 1.76× faster, cached calls were approximately unchanged, and offline calls were 1.16× faster.

Full results, provenance and raw evidence

AI Disclosure

  • OpenAI Codex assisted with implementation, tests, and PR drafting.
  • all fixes and drafts have been human-architected, human-directed and human-reviewed before publication of PR requests.

…-structured-output

# Conflicts:
#	crates/dspy-rs/src/core/lm/mod.rs
#	crates/dspy-rs/src/trace/span.rs

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.

Performance Optimization for DSPy vs DSRs

1 participant