refactor(llm): fold cache policy and option merge into one request rebuild - #41271
Open
Celibistrial wants to merge 1 commit into
Open
refactor(llm): fold cache policy and option merge into one request rebuild#41271Celibistrial wants to merge 1 commit into
Celibistrial wants to merge 1 commit into
Conversation
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.
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
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.
Issue for this PR
Closes #41269
Type of change
What does this PR do?
compile()ran the option merge and the cache policy as two separateLLMRequest.updatecalls. 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 testinpackages/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