Skip to content

perf(scopes): avoid cloning full-frame samples on draw (#81) - #95

Open
liangshengsheng12333 wants to merge 2 commits into
OakVideoEditorCommunity:mainfrom
liangshengsheng12333:perf/scopes-no-clone-81
Open

liangshengsheng12333 wants to merge 2 commits into
OakVideoEditorCommunity:mainfrom
liangshengsheng12333:perf/scopes-no-clone-81

Conversation

@liangshengsheng12333

Copy link
Copy Markdown

Summary

Fixes #81.

Previously, LumaDataSource::luma_samples and ChromaDataSource::chroma_samples returned a freshly cloned Vec on every read, and ScopeState also cloned (*scope.luma) / (*scope.chroma) when updating from ScopeData. On high-resolution (e.g., 4K) frames, this added full-frame allocations and copies on the scopes draw path.

Changes

  • crates/oak-app/src/widgets/scopes/mod.rs:
    • Change LumaDataSource::luma_samples(&self) to return &[f32] and ChromaDataSource::chroma_samples(&self) to return &[(f32, f32)].
    • Update Histogram::bins, Waveform::envelope, Vectorscope::points, and the MockLuma / MockChroma test sources to borrow slices directly without cloning.
    • Assert slice pointer identity (ptr::eq) against the underlying buffers in scopes_render_from_mock_data.
  • crates/oak-app/src/panels/program_viewer.rs:
    • Store Arc<Vec<f32>> and Arc<Vec<(f32, f32)>> in ScopeState instead of owned Vecs, and share scope.luma / scope.chroma Arc handles directly on frame updates.
    • Return borrowed slices (&self.luma / &self.chroma) from ScopeState's LumaDataSource and ChromaDataSource implementations so drawing and paused redraws incur zero full-frame copies.
  • crates/oak-app/src/panels/program_viewer/tests.rs:
    • Extend scopes_tab_renders_from_the_current_frame to assert Arc::ptr_eq between ScopeState and engine ScopeData, slice pointer identity (ptr::eq), and buffer reuse across paused redraws.

Testing

  • rustfmt --edition 2024 --check on all modified files: passed.
  • python tooling/check_sdk_consumers.py: passed.
  • rustc --edition 2024 --test crates/oak-app/src/widgets/scopes/math.rs: 10/10 unit tests passed.
  • Note: Full cargo test -p oak-app relies on CI (local checkout lacks the quercus-engine submodule).

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.

[v0.6] Scopes: avoid cloning full-frame samples on every draw

1 participant