mirror of
https://github.com/NickeManarin/ScreenToGif.git
synced 2026-04-25 07:05:54 +03:00
[PR #1409] Parallelize capture saving to disk for ImageCapture #1359
Labels
No labels
copy cats
duplicated
future feature
pull-request
⬜ Accepted
⬜ Completed
⬜ Help Wanted 💪
⬜ In Progress
⬜ Missing Details
⬜ Pending
⬜ Waiting For Answer ⏳
🆕 feature preview
🔷 Bug 🐛
🔷 Out Of Scope
🔷 Out Of Scope
🔷 Question
🔷Enhancement
🔷Enhancement
🔷Invalid / External
🔷Knowledge Base
🔷Won't Fix
🕑 High
🕑 High
🕑 High
🕕 Medium
🕙 Low
🕛 Critical
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ScreenToGif#1359
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/NickeManarin/ScreenToGif/pull/1409
Author: @Wouterdek
Created: 8/24/2025
Status: 🔄 Open
Base:
master← Head:feature/parallel-saving📝 Commits (1)
8644c84Parallelize capture saving to disk for ImageCapture📊 Changes
3 files changed (+74 additions, -16 deletions)
View changed files
📝
ScreenToGif/Capture/BaseCapture.cs(+46 -14)📝
ScreenToGif/Capture/DirectImageCapture.cs(+14 -1)📝
ScreenToGif/Capture/ImageCapture.cs(+14 -1)📄 Description
This PR adds additional capture consumer tasks, which are hinted to run in parallel. These tasks speed up the encoding and saving process, which was previously a bottleneck causing large memory usage and long waiting times at the end of recording. The degree of parallelization is set conservatively to avoid overwhelming the CPU on weaker systems. It is currently hardcoded at 25% of cpu cores (16 cores => 4 tasks, 12 cores => 3 tasks, 8 cores => 2 tasks, <8 cores => 1 task, ...)
This change is implemented for ImageCapture and DirectImageCapture, other capture methods are unchanged.
Performance
Before this change, recording 2 minutes of 1080p 60hz would spike my RAM usage up to 30GB and take over a minute of "Stopping..." before proceeding to the editor.
After this change, I can record 4k 60hz with RAM usage below 800MB and the editor immediately opens after stopping recording.
Safety
Capture()andSave()already run async with a blocking collection, which made it easier to implement this change. However, when saving multiple frames in parallel, multiple frames may try to append toProject.Framesat the same time. I've put a lock around that line to avoid race conditions corrupting the list. Also, a later frame may finish before an earlier one, so frames may be saved out of order. Therefore, I've added a post-process sorting step to ensure a correct order ofProject.Frames.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.