-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Improve export speed (reduced total time by ~16%) #1158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47ed0c1
feat: Add export benchmark test
richiemcilroy df79062
feat: refactor frame conversion and improve threading, buffers
richiemcilroy 715c050
move utils to export test
Brendonovich 953d0b0
don't repeatedly poll buffer
Brendonovich 8b02f88
Merge branch 'main' into rendering-speed
Brendonovich e249093
fix export benchmark
Brendonovich e0c562d
reduce export buffer sice
Brendonovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(pnpm typecheck:*)", | ||
| "Bash(pnpm lint:*)", | ||
| "Bash(pnpm build:*)" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(pnpm typecheck:*)", | ||
| "Bash(pnpm lint:*)", | ||
| "Bash(pnpm build:*)", | ||
| "Bash(cargo check:*)" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| use std::{ | ||
| path::PathBuf, | ||
| sync::{ | ||
| Arc, | ||
| atomic::{AtomicU32, Ordering}, | ||
| }, | ||
| time::{Duration, Instant}, | ||
| }; | ||
Brendonovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| use cap_export::{ | ||
| ExporterBase, | ||
| mp4::{ExportCompression, Mp4ExportSettings}, | ||
| }; | ||
| use cap_project::XY; | ||
|
|
||
| async fn run_export(project_path: PathBuf) -> Result<(PathBuf, Duration, u32), String> { | ||
| let exporter_base = ExporterBase::builder(project_path.clone()) | ||
| .build() | ||
| .await | ||
| .map_err(|err| format!("Exporter build error: {err}"))?; | ||
|
|
||
| let settings = Mp4ExportSettings { | ||
| fps: 60, | ||
| resolution_base: XY::new(1920, 1080), | ||
| compression: ExportCompression::Minimal, | ||
| }; | ||
|
|
||
| let start = Instant::now(); | ||
| let last_frame = Arc::new(AtomicU32::new(0)); | ||
| let frame_counter = Arc::clone(&last_frame); | ||
|
|
||
| let output_path = settings | ||
| .export(exporter_base, move |frame| { | ||
| frame_counter.store(frame, Ordering::Relaxed) | ||
| }) | ||
| .await | ||
| .map_err(|err| format!("Exporter error: {err}"))?; | ||
|
|
||
| let elapsed = start.elapsed(); | ||
| let frames = last_frame.load(Ordering::Relaxed); | ||
|
|
||
| if frames == 0 { | ||
| return Err("No frames were rendered during export".into()); | ||
| } | ||
|
|
||
| Ok((output_path, elapsed, frames)) | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| #[ignore] | ||
| async fn export_latest_recording_benchmark() -> Result<(), Box<dyn std::error::Error>> { | ||
| let recordings = list_recordings(); | ||
|
|
||
| println!("Found {} recordings", recordings.len()); | ||
|
|
||
| if recordings.is_empty() { | ||
| return Err( | ||
| "No recordings found. Add a Cap recording before running this benchmark.".into(), | ||
| ); | ||
| } | ||
|
|
||
| let Some(project_path) = recordings.first() else { | ||
| unreachable!("recordings list cannot be empty here"); | ||
| }; | ||
|
|
||
| println!("Using project: {}", project_path.display()); | ||
|
|
||
| let (output_path, duration, frames) = run_export(project_path.clone()).await?; | ||
|
|
||
| let fps = frames as f64 / duration.as_secs_f64(); | ||
| println!( | ||
| "Export completed in {:.2?} ({} frames, {:.2} fps). Output: {}", | ||
| duration, | ||
| frames, | ||
| fps, | ||
| output_path.display() | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn get_recordings_dir() -> Option<PathBuf> { | ||
| let mut candidates: Vec<PathBuf> = Vec::new(); | ||
|
|
||
| for app_name in ["Cap - Development", "Cap"] { | ||
| if let Some(proj_dirs) = ProjectDirs::from("so", "cap", app_name) { | ||
| candidates.push(proj_dirs.data_dir().join("recordings")); | ||
| } | ||
| } | ||
|
|
||
| if let Some(base_dirs) = BaseDirs::new() { | ||
| let data_dir = base_dirs.data_dir(); | ||
| for identifier in ["so.cap.desktop.dev", "so.cap.desktop"] { | ||
| candidates.push(data_dir.join(identifier).join("recordings")); | ||
| } | ||
| } | ||
|
|
||
| candidates.into_iter().find(|dir| dir.exists()) | ||
| } | ||
|
|
||
| pub fn list_recordings() -> Vec<PathBuf> { | ||
| let Some(recordings_dir) = get_recordings_dir() else { | ||
| return Vec::new(); | ||
| }; | ||
|
|
||
| let Ok(entries) = fs::read_dir(&recordings_dir) else { | ||
| return Vec::new(); | ||
| }; | ||
|
|
||
| let mut recordings: Vec<(SystemTime, PathBuf)> = entries | ||
| .filter_map(|entry| { | ||
| let entry = entry.ok()?; | ||
| let path = entry.path(); | ||
|
|
||
| if !path.is_dir() { | ||
| return None; | ||
| } | ||
|
|
||
| if !path.join("project-config.json").exists() | ||
| || !path.join("recording-meta.json").exists() | ||
| { | ||
| return None; | ||
| } | ||
|
|
||
| let created = path | ||
| .metadata() | ||
| .and_then(|m| m.created()) | ||
| .unwrap_or(SystemTime::UNIX_EPOCH); | ||
|
|
||
| Some((created, path)) | ||
| }) | ||
| .collect(); | ||
|
|
||
| recordings.sort_by(|a, b| b.0.cmp(&a.0)); | ||
|
|
||
| recordings.into_iter().map(|(_, path)| path).collect() | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.