Skip to content

Optimize ImageReader frame generation with cached QImage - #1129

Open
rajeshgk wants to merge 1 commit into
OpenShot:developfrom
rajeshgk:perf/imagereader-qimage-cache-202
Open

rajeshgk wants to merge 1 commit into
OpenShot:developfrom
rajeshgk:perf/imagereader-qimage-cache-202

Conversation

@rajeshgk

Copy link
Copy Markdown
Contributor

Summary

Optimize ImageReader::GetFrame() by caching the ImageMagick-to-QImage conversion once per reader open cycle.

Previously, each requested frame performed a full image conversion, even though the source image remained unchanged.

Changes

  • Cache the converted QImage for repeated frame requests.
  • Use Qt implicit sharing with separate QImage wrappers to preserve frame independence and copy-on-write behavior.
  • Invalidate cached image data when closing or reopening the reader.
  • Synchronize reader lifecycle and cache access.
  • Add regression tests covering caching, frame independence, and reader lifecycle behavior.

Performance

Measured using the same PNG image, 100 warm-up calls, and five repetitions of 1,000 frame requests per implementation.

Debug build, GCC 15, Qt 5, ImageMagick 7.

Implementation Median latency
Baseline 1,750.015 µs/frame
Optimized 2.233 µs/frame

Measured speedup: approximately 783.7x.

Both benchmark runs produced the same checksum: 3672000.

These measurements represent warm-cache GetFrame() microbenchmark performance, not end-to-end playback speed.

Validation

  • ImageReader regression tests: 30 assertions across four test cases passed.
  • git diff --check: passed.
  • Full test suite previously executed: 587 of 589 tests passed.
  • Two spherical metadata tests also failed on the unmodified baseline and are unrelated to this change.

Compatibility consideration

Adding cached-image and synchronization members changes the ImageReader class layout. This may affect ABI compatibility for existing binary consumers and should be considered during review.

Related issue

Addresses #202.

Cache ImageMagick-to-QImage conversion once per open cycle.

Use Qt implicit sharing with separate QImage wrappers to preserve frame independence.

Synchronize reader lifecycle and cache access, and add regression tests.

Addresses OpenShot#202.
@rajeshgk

Copy link
Copy Markdown
Contributor Author

@jonoomph

When you have an opportunity, could you please review this
ImageReader performance optimization?

The change caches the ImageMagick-to-QImage conversion and
uses Qt implicit sharing to avoid repeated conversion work.

Validation completed:

  • All 9 automated PR checks passed.
  • ImageReader regression tests: 30 assertions passed.
  • Codacy static analysis passed.
  • Source licensing validation passed.
  • PR is mergeable.

Performance benchmark (Debug, warm cache):

  • Baseline: 1,750.015 microseconds/frame
  • Optimized: 2.233 microseconds/frame
  • Approximately 783.7x faster GetFrame() calls

The benchmark measures repeated frame retrieval, not
end-to-end application playback performance.

One compatibility consideration is that the additional
cache and synchronization members change the ImageReader
class layout, potentially affecting ABI compatibility.

Feedback and requested adjustments are welcome.

Thank you!

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.

1 participant