Skip to content

refactor(llm): fold cache policy and option merge into one request rebuild - #41271

Open
Celibistrial wants to merge 1 commit into
anomalyco:devfrom
Celibistrial:perf/llm-single-request-rebuild
Open

refactor(llm): fold cache policy and option merge into one request rebuild#41271
Celibistrial wants to merge 1 commit into
anomalyco:devfrom
Celibistrial:perf/llm-single-request-rebuild

Conversation

@Celibistrial

Copy link
Copy Markdown

Issue for this PR

Closes #41269

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

compile() ran the option merge and the cache policy as two separate LLMRequest.update calls. The constructor re-decodes the whole message history each time, so long conversations paid that decode twice per request. The two merges write disjoint fields (generation/providerOptions/http vs tools/system/messages) and both read only from the original request, so I changed each to return a patch and applied one update. Same output, one rebuild instead of two.

How did you verify your code works?

bun test in packages/llm (cache-policy and adapter suites pass). I also added a small benchmark, test/perf/cache-policy-single-update.bench.test.ts, that builds a realistic request and compares the two-update path against the folded one. It reports about 1.9x on the rebuild step locally.

Screenshots / recordings

N/A, not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

compile() called applyCachePolicy(resolveRequestOptions(request)), and each
LLMRequest.update re-decodes the whole message history in the constructor. The
two merges touch disjoint fields, so return them as patches and rebuild once.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title perf(llm): fold cache policy and option merge into one request rebuild doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@Celibistrial Celibistrial changed the title perf(llm): fold cache policy and option merge into one request rebuild refactor(llm): fold cache policy and option merge into one request rebuild Aug 8, 2026
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.

perf: cache policy and option merge each rebuild the LLM request

1 participant