Skip to content

Optimize memory usage#4

Merged
gregberge merged 2 commits intomainfrom
memory-optimization
Jan 14, 2026
Merged

Optimize memory usage#4
gregberge merged 2 commits intomainfrom
memory-optimization

Conversation

@gregberge
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings January 14, 2026 12:26
@gregberge gregberge force-pushed the memory-optimization branch from 0ecf967 to 0c7f571 Compare January 14, 2026 12:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to optimize memory usage in the image fingerprinting code by introducing memory limits, removing the integral image approach, and implementing early buffer cleanup strategies.

Changes:

  • Added max_bytes configuration option with validation (minimum 1MB)
  • Replaced integral image algorithm with direct cell counting in hash_grid_density_no_integral
  • Implemented early RGBA buffer cleanup in fingerprint_rgba_for_equality_owned
  • Added FingerprintDiffTask struct for async processing (incomplete)
  • Removed build_integral_image, rect_sum, and get_integral functions

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/lib.rs Core memory optimization changes including max_bytes option, new hash algorithm without integral images, early buffer cleanup, and incomplete refactoring of fingerprint_diff function
index.d.ts Added maxBytes optional property to JsEqualityFingerprintOptions interface
Comments suppressed due to low confidence (1)

src/lib.rs:233

  • The function references variables and enum variants that don't exist in the current code path. After the match expression at lines 214-224, the code tries to destructure 'input' using InputBytes::File and InputBytes::Buffer (lines 227-228), but these variants don't match either the local enum definition (lines 209-212) or the module-level enum (lines 158-161). Additionally, line 231 calls decode_png_to_rgba with png_bytes (a slice), but the new signature expects a BufReader. Line 233 calls fingerprint_rgba_for_equality which no longer exists - it was renamed to fingerprint_rgba_for_equality_owned and now takes ownership of the rgba vector.
  let png_bytes: &[u8] = match &input {
    InputBytes::File(bytes) => bytes.as_slice(),
    InputBytes::Buffer(buffer) => buffer.as_ref(),
  };

  let (rgba, width, height) = decode_png_to_rgba(png_bytes)?;
  let opts = build_options(options)?;
  Ok(fingerprint_rgba_for_equality(&rgba, width, height, &opts))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@gregberge gregberge force-pushed the memory-optimization branch from 0c7f571 to 26bcdcb Compare January 14, 2026 12:44
@gregberge gregberge force-pushed the memory-optimization branch from 26bcdcb to 7d1bd33 Compare January 14, 2026 12:51
@gregberge gregberge changed the title chore: more memory optimization Optimize memory usage Jan 14, 2026
@gregberge gregberge merged commit 843b0ea into main Jan 14, 2026
12 checks passed
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.

2 participants