perf: replace JSON deep-clone with structuredClone in RAG cache functions - #79
Merged
BigSimmo merged 1 commit intoJun 27, 2026
Conversation
Copilotcreated this pull request from a session on behalf of BigSimmoJune 27, 2026 07:32 View session
BigSimmo
marked this pull request as ready for review
June 27, 2026 12:38
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Uh oh!
There was an error while loading. Please reload this page.
BigSimmo
deleted the
copilot/task-87357024-1243497866-26178f79-0b72-4b9d-a4e5-d0500fca33c6
branch
June 27, 2026 12:38
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the hottest RAG cache read/write paths by replacing JSON round-trip deep cloning with structuredClone in src/lib/rag.ts, reducing CPU overhead and avoiding string serialization for large nested objects.
Changes:
- Replace
JSON.parse(JSON.stringify(...))withstructuredClone(...)incloneAnswer. - Replace
JSON.parse(JSON.stringify(...))withstructuredClone(...)incloneSearchResults.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 freeto 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.
cloneAnswerandcloneSearchResultsinrag.tsusedJSON.parse(JSON.stringify(...))to deep-clone on every cache read and write. These run in the hottest paths (search + answer generation) on large nested objects.structuredCloneskips string serialisation entirely — 3–10× faster for this data shape on Node 24.Same change applied to
cloneSearchResults.Verification
npm run verify:cheapnpm run verify:uiwhen UI, routing, styling, browser behavior, reduced-motion, or forced-colors behavior changednpm run verify:releasebefore release or handoff confidence claimsnpm run format:checknpm run check:production-readinesswhen clinical workflow, privacy, environment, Supabase, source governance, or deployment behavior changedClinical Governance Preflight
Complete this section when the change touches ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output.
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
RagAnswerandSearchResultare plain-data objects with noDate,Map,Set, functions, or symbols —structuredClonesemantics are identical to the JSON round-trip for these types.