← Back to PRs

#3895: perf: mathematical optimization of vision pipeline via deterministic scaling

by adarshsen592-create open 2026-01-29 09:40 View on GitHub →
This PR addresses the high CPU overhead and memory crashes in the screenshot normalization process (Fixes #3870, #3875). Changes: > - Replaced iterative resizing loops with a single-pass O(1) scale calculation. Implemented area-to-byte proportionality logic (Square Root Law) for precise sizing. Reduced ingestion latency significantly for high-resolution displays. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR replaces the prior “grid search” screenshot normalization (multiple resize+quality attempts until under `maxBytes`) with a single-pass deterministic scaling computation based on dimension and byte-budget ratios. The change is localized to `src/browser/screenshot.ts`, which is used by the browser snapshot routes to constrain screenshot payload size before saving/serving. Main issues: - The updated file currently references removed imports/constants (`getImageMetadata`, `resizeToJpeg`, `DEFAULT_BROWSER_SCREENSHOT_MAX_*`), which should break compilation. - The new return type/contentType implies JPEG output for all paths, but the early-exit can return a non-JPEG input buffer while labeling it as `image/jpeg`. - The deterministic byte scaling is heuristic; without a post-check/fallback, outputs can still exceed `maxBytes` for certain screenshot content. <h3>Confidence Score: 1/5</h3> - Not safe to merge as-is due to likely compile/runtime breakage and incorrect contentType guarantees. - `src/browser/screenshot.ts` appears to have removed required imports/exports but still references them, which should fail to build. Additionally, the function now claims to always return JPEG while the early-exit can return the original (possibly PNG) buffer, which can break downstream consumers relying on contentType/buffer alignment. - src/browser/screenshot.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs