perf: fix all performance issues from issue list#83
Draft
Copilot wants to merge 2 commits into
Draft
Conversation
TypeScript fixes: - #77: Remove JSON.stringify indentation in store.ts and settings-store.ts - #76: Replace Math.max spread with reduce in agent-history/index.ts - #73: Replace JSON.stringify field check with .some() in gateway/bridge/input.ts - #71: Replace Math.max spread with loop in usage/store.ts - #70: Cache mergedPricing() to avoid repeated disk reads - #74: Replace Array.shift() with index pointer in ThinkingState.prune() - #75: Add LRU eviction to conversations/thinkingStates maps in adapter.ts - #69: Avoid duplicate collectFiles() calls in session-cache.ts - #68: Read only first 64KB per file in agent-history scanners (avoid full read) Rust fixes: - #63: Direct ElementInfo→HoverElement conversion without JSON round-trip - #60: Switch template scaling from Lanczos3 to Triangle in find_image.rs - #61: Remove intermediate Vec allocation in precompute_template - #59: Use Cow<GrayImage> to avoid cloning full screenshot when no region - #58/#57: Add HashMap index to ScreenshotCache and ImageCache for O(1) lookup - #56: Eliminate JPEG→PNG round-trip in take_screenshot handler Agent-Logs-Url: https://github.com/unbug/tday/sessions/89e1f6c9-ee1f-48d4-a8ea-5684c1298897 Co-authored-by: unbug <799578+unbug@users.noreply.github.com>
- Fix evictOldest() to use while loop instead of if (adapter.ts) - Fix UTF-8 boundary handling in readFirstLines() using StringDecoder (scanners.ts) - Rewrite ImageCache to use HashMap + VecDeque<key> without position indices (image_cache.rs) - Rewrite ScreenshotCache to use HashMap + VecDeque<key> without position indices (screenshot_cache.rs) Agent-Logs-Url: https://github.com/unbug/tday/sessions/89e1f6c9-ee1f-48d4-a8ea-5684c1298897 Co-authored-by: unbug <799578+unbug@users.noreply.github.com>
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.
Fixes 15 performance-related issues found in the issue tracker.
TypeScript/Node.js fixes:
JSON.stringify(…, null, 2)indentation instore.tsandsettings-store.ts(machine-read files don't need pretty-printing)Math.max(...files.map(f => f.mtime))spread (stack-unsafe for large arrays) with.reduce()inagent-history/index.tsJSON.stringify(input).includes('reasoning_content')withinput.some(item => 'reasoning_content' in item)ingateway/bridge/input.tsto avoid full serialisationMath.max(...tsValues)spread with a simple min/max loop inusage/store.tsmergedPricing()result to avoid re-readingpricing.jsonon every usage query; addinvalidatePricingCache()for updatesArray.shift()with a head-index pointer inThinkingState.prune()(gateway/deepseek/state.ts)evictOldest()(withwhileloop) to enforce LRU eviction onconversationsandthinkingStatesMaps inadapter.tscollectFiles()twice per dirty agent insession-cache.tsby returning{ dirty, files }fromisAgentDirty()readFileSync+ split with a synchronous 64 KB chunk read usingopenSync/readSyncin all agent-history scanners; useStringDecoderto safely handle multi-byte UTF-8 at the chunk boundaryRust fixes:
serde_json::to_value(&info)+parse_hover_element()round-trip inhover_tracker.rswith direct field mapping; re-exportElementInfofrom each platform moduleLanczos3toTriangleinfind_image.rs(~4× faster with acceptable quality loss for template matching)Vec<f64>allocation inprecompute_templatewith a two-pass (mean then norm) loop over the image pixelsCow<GrayImage>infind_imageto borrow the screenshot directly when no search region is specified, avoiding a full cloneVecDeque<CachedScreenshot/CachedImage>withHashMap<id, data>+VecDeque<id>for O(1) lookups inScreenshotCacheandImageCachespawn_blockingJPEG→PNG round-trip inhandle_take_screenshot; both the JPEG (for the response) and PNG (for the cache) are now produced in a single blocking task