Skip to content

feat: CPU utilization optimization in image diff calculations#146

Merged
abelonogov-ld merged 48 commits intomainfrom
andrey/exportdiff-2longhash-swiftpackage-r
Mar 6, 2026
Merged

feat: CPU utilization optimization in image diff calculations#146
abelonogov-ld merged 48 commits intomainfrom
andrey/exportdiff-2longhash-swiftpackage-r

Conversation

@abelonogov-ld
Copy link
Copy Markdown
Contributor

@abelonogov-ld abelonogov-ld commented Mar 5, 2026

  • 20x for DEBUG 20x for RELEASE improvement in image comparison
  • Use low-level coding techniques to calculate tile signatures faster

Note

High Risk
Replaces a core image-diff primitive with new low-level C/NEON code and unsafe buffer plumbing, which could affect correctness or stability of session replay capture if edge cases slip through.

Overview
Major perf change: Tile signature generation used for image diffs is rewritten to use a new SessionReplayC target (C + optional ARM NEON), replacing the prior Swift/CommonCrypto SHA-256 per-tile hashing with a faster non-crypto 128-bit style hash and centralized tile layout computation.

TileSignatureManager now calls tile_compute_layout/tile_compute_all and reuses an internal C buffer; ImageSignature is split into its own file and now precomputes an accumulated hash to speed dictionary lookups/equality.

Validation/benchmarking: Adds TileHashParityTests to ensure NEON and scalar paths match, updates the benchmark tooling/UI to measure signature computation, and forces decoded frame images in RawFrameReader for more consistent pixel access. Packaging is updated so CocoaPods and SPM both build/link the new SessionReplayC module.

Written by Cursor Bugbot for commit d3604f4. This will update automatically on new commits. Configure here.

(cherry picked from commit 78ad485)
…anvas buffer limit. Updated makeExportFrame to accept keyFrameId and isKeyframe parameters. Adjusted canvasBufferLimit to account for keyframe logic. Added test to verify mutation appending when canvas buffer limit is exceeded for non-keyframes.
- Added support for command-line options including scheme, destination, only-testing, skip-testing, and test-file.
- Introduced a usage function to display help information.
- Implemented a function to derive test identifiers from file paths.
- Refactored the test execution command to accommodate new options and improve readability.

(cherry picked from commit cd1e1e2)
(cherry picked from commit 54853ad)
… allowing multiple runs. Updated BenchmarkExecutor to return execution time alongside bytes, and modified BenchmarkView to display execution time in results.
* main:
  chore: Make agents able to run unit tests (#141)
  chore(main): release 0.20.0 (#140)

# Conflicts:
#	Tests/SessionReplayTests/RRWebEventGeneratorTests.swift
#	test.sh
- Updated the ExportFrame structure to replace TileSignature with ImageSignature in AddImage and RemoveImage.
- Adjusted RRWebEventGenerator and related methods to accommodate the new image signature handling.
- Modified unit tests to ensure compatibility with the updated ExportFrame parameters.
(cherry picked from commit 37b2dfd1eb49b3e6f0e64441523119dc2a9111fb)
…ash-swiftpackage

* andrey/exportdiffmanager:
  separated time
  Alert errors
  do account disk reading into benchmark

# Conflicts:
#	Sources/LaunchDarklySessionReplay/BenchMark/BenchmarkExecutor.swift
* main:
  chore(main): release 0.22.0 (#145)
  feat: Moves compression before buffer (Optimization) (#144)
  chore(main): release 0.21.0 (#143)
  feat: Bridging hooks calls from MAUI (#142)

# Conflicts:
#	Sources/LaunchDarklySessionReplay/BenchMark/BenchmarkExecutor.swift
#	Sources/LaunchDarklySessionReplay/ScreenCapture/TileSignatureManager.swift
#	TestApp/Sources/BenchmarkView.swift
@abelonogov-ld abelonogov-ld requested review from a team and mario-launchdarkly as code owners March 5, 2026 22:01
@abelonogov-ld abelonogov-ld enabled auto-merge (squash) March 5, 2026 22:53
@abelonogov-ld abelonogov-ld disabled auto-merge March 6, 2026 02:52
@abelonogov-ld abelonogov-ld enabled auto-merge (squash) March 6, 2026 20:13
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

result.hashHi = (int64_t)h1;
return result;
}
#endif
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NEON function guard mismatch causes debug build linker error

High Severity

The tile_hash_w64_neon function is declared in the header under #if defined(__ARM_NEON) but its implementation is guarded by #if USE_NEON, which requires both __ARM_NEON and __OPTIMIZE__. In debug builds on ARM (devices and Apple Silicon simulators), __OPTIMIZE__ is not defined, so the declaration is visible but the symbol is never compiled. The parity tests in TileHashParityTests.swift call tile_hash_w64_neon unconditionally, resulting in a linker error in any non-optimized ARM build.

Additional Locations (1)

Fix in Cursor Fix in Web

@abelonogov-ld abelonogov-ld merged commit 80e0cf8 into main Mar 6, 2026
5 checks passed
@abelonogov-ld abelonogov-ld deleted the andrey/exportdiff-2longhash-swiftpackage-r branch March 6, 2026 20:16
abelonogov-ld pushed a commit that referenced this pull request Mar 7, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.23.0](0.22.0...0.23.0)
(2026-03-06)


### Features

* CPU utilization optimization in image diff calculations
([#146](#146))
([80e0cf8](80e0cf8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk: this PR only updates version numbers and release notes (no
runtime code changes beyond `sdkVersion` constant).
> 
> **Overview**
> Releases version `0.23.0` by updating the release manifest, CocoaPods
podspec versions, and the exported `sdkVersion` constant.
> 
> Updates `CHANGELOG.md` with the `0.23.0` entry noting a CPU
utilization optimization in image diff calculations.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
db4a44b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants