-
Notifications
You must be signed in to change notification settings - Fork 1
⚡ Skip image type detection when SDK provides explicit type #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Client SDK now sends 'type' field ('base64' or 'file-path')
- Server uses explicit type, skipping O(n) detection entirely
- Fallback detection optimized with length check (> 2KB = not a path)
- Fixed looksLikeFilePath to not false-positive on JPEG base64 (/9j/...)
This eliminates expensive regex validation on multi-megabyte screenshots.
760d73a to
6b640f2
Compare
Pull Request ReviewOverviewThis PR introduces a smart performance optimization by having the client SDK explicitly declare the image type ('base64' or 'file-path'), eliminating expensive O(n) regex validation on large screenshot buffers. The optimization is well-designed with proper fallback for backwards compatibility. ✅ Strengths1. Performance Optimization
2. Backwards Compatibility
3. Code Quality
|
- Add tests for type parameter in router, tdd-handler, api-handler - Add tests for length optimization and JPEG base64 edge case - Align length thresholds to 1000 (was inconsistent 1000 vs 2000) - Add validation for type parameter (invalid values fall back to detection)
## Summary Adds the `type` field to all SDK clients that send screenshot image data. This completes the performance optimization from #174 by ensuring all clients benefit from O(1) type detection on the server. ## Changes | SDK | File | Type Sent | |-----|------|-----------| | Full SDK | `src/sdk/index.js` | `type: 'base64'` | | Vitest | `clients/vitest/src/setup.js` | `type: 'file-path'` | | Ruby | `clients/ruby/lib/vizzly.rb` | `type: 'base64'` | | Swift | `clients/swift/.../VizzlyClient.swift` | `type: 'base64'` | **No changes needed:** - **Core client** (`src/client/index.js`) - Already updated in #174 - **Static-site** - Uses core client SDK - **Storybook** - Uses core client SDK - **Ember** - Different architecture (sends selector, server takes screenshot) ## Packages to Release After merging, the following packages need new releases: | Package | Registry | Notes | |---------|----------|-------| | `@vizzly-testing/cli` | npm | Main CLI package | | `@vizzly-testing/vitest` | npm | Vitest plugin | | `vizzly` | RubyGems | Ruby gem | | `Vizzly` | Swift Package Manager | Swift package | ## Test Plan - [x] All 1751 tests pass - [x] Backwards compatible (server falls back to detection if `type` missing)
Summary
typefield ('base64'or'file-path') with screenshot requestslooksLikeFilePathto not false-positive on JPEG base64 (which starts with/9j/)Problem
For large full-page screenshots (multi-megabyte base64 strings), the
detectImageInputTypefunction was running expensive O(n) regex validation on every screenshot. This caused noticeable slowdowns, especially for content-heavy pages like blog indexes and changelogs.Solution
Test plan
typefield still work