Skip to content

Optimize inference preprocessing pipeline - #787

Draft
xav-ie wants to merge 4 commits into
royshil:mainfrom
xav-ie:pr/optimize-inference-preprocessing
Draft

Optimize inference preprocessing pipeline#787
xav-ie wants to merge 4 commits into
royshil:mainfrom
xav-ie:pr/optimize-inference-preprocessing

Conversation

@xav-ie

@xav-ie xav-ie commented Feb 26, 2026

Copy link
Copy Markdown

Summary

  • Computes image similarity PSNR on a 192×108 thumbnail instead of the full frame, reducing the comparison cost by ~99% of pixels while preserving change detection fidelity
  • Reorders the inference preprocessing to resize BGRA first and then convert to RGB, so cvtColor operates on the smaller network-input-sized image instead of the full frame
  • Switches preprocessing resize interpolation from INTER_LINEAR to INTER_NEAREST since the result feeds directly into a neural network that is invariant to interpolation quality

Benchmark results (300 iterations, best of 3 runs)

Step Median (µs/frame) Change
Baseline 2532.0
+ Thumbnail PSNR 1731.4 −32%
+ Resize before cvtColor + INTER_NEAREST 1127.7 −35%
Cumulative 1127.7 −55%

Pull Request Checklist

Please read our latest CONTRIBUTING.md.

  • I have read the latest CONTRIBUTING.md.
  • I have acknowledged the licensing and patent grant policy.
  • I have included the required license headers.
  • I am confident with my code integrity.
  • I have signed off and verified all my commits.

@royshil royshil left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Did you test this with all models?

Comment thread src/background-filter.cpp Outdated
}
}
tf->lastImageBGRA = imageBGRA.clone();
tf->lastImageBGRA = thumbnail;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is the last image only used for PSNR calculations?
If so I suppose it's fine

@umireon
umireon requested review from royshil and removed request for royshil February 27, 2026 03:45
@xav-ie

xav-ie commented Feb 27, 2026

Copy link
Copy Markdown
Author

Did you test this with all models?

No, sorry. Let me try to figure this out. Sorry for the noise.

@xav-ie
xav-ie marked this pull request as draft February 27, 2026 04:16

@umireon umireon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Working on the CONTRIBUTING.md now. Sorry but wait a moment, please.

@umireon
umireon dismissed their stale review February 27, 2026 17:54

Checklist added

xav-ie added 2 commits March 8, 2026 00:04
Extract shared pipeline helper functions (render_write, tick_read,
check_similarity, preprocess_for_inference) into src/pipeline-helpers.h
for use by both the plugin and a standalone benchmark.

The benchmark exercises the same code paths as the plugin:
  1. Render thread writes frame to shared buffer (clone)
  2. Tick thread reads frame from shared buffer (clone)
  3. Similarity check via full-frame PSNR
  4. Preprocessing: cvtColor(BGRA→RGB) then resize

Reports per-frame timing (mean/median/p95), hardware perf counters
(cache-misses, LLC-store-misses via perf_event_open), and optionally
measures CPU utilization with a real ONNX Runtime thread pool at 30fps.

Signed-off-by: Xavier Ruiz <github@xav.ie>
Set session.intra_op.allow_spinning=0 and
session.inter_op.allow_spinning=0 to prevent ORT worker threads
from busy-waiting between inference calls.  This eliminates idle
CPU burn without affecting inference latency.

Signed-off-by: Xavier Ruiz <github@xav.ie>
@xav-ie
xav-ie force-pushed the pr/optimize-inference-preprocessing branch from e90246d to af7c862 Compare March 8, 2026 05:07
xav-ie added 2 commits March 8, 2026 00:11
Signed-off-by: Xavier Ruiz <github@xav.ie>
…eline

Signed-off-by: Xavier Ruiz <github@xav.ie>
@xav-ie
xav-ie force-pushed the pr/optimize-inference-preprocessing branch from af7c862 to 7fde9c5 Compare March 8, 2026 05:12
@royshil

royshil commented Mar 15, 2026

Copy link
Copy Markdown
Owner

@xav-ie do you want to bring this up so we can incorporate in the plugin? this is a very good contribution

@umireon umireon added the auto-review Turn on this when PR is ready label Mar 15, 2026
@umireon umireon added this to the 1.4.1 milestone Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-review Turn on this when PR is ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants