Convert as much at once as the Mac can stand, and no more - #28
Merged
Merged
Conversation
One number decided how much ran at once, and it was wrong in both directions: two videos at a time is one too many, because the media engine is a single piece of hardware and asking it for two only makes heat, while two images at a time is far too few on a machine with ten cores. The limit is now per kind of work, computed from the cores, the memory and whether this is Apple silicon - images bounded by memory, since a decoded photograph is a quarter of a gigabyte and eight at once is how a batch takes a Mac down. Nothing here decides which chip does the work. Core Image goes to the GPU, Vision to the neural engine, VideoToolbox to the media engine, and Apple routes that without being asked. It backs off while a batch is running: a warm Mac, low power mode or memory pressure halves the limits or drops them to one, and they come back when the pressure does not. The screen says so rather than just getting slower. Pause stops new files starting and lets the ones in flight finish - a native encode cannot be frozen halfway and a button claiming otherwise would be lying. Cancel now reaches one file as well as all of them, and reaches a subprocess: a cancelled conversion used to drop the task and leave ffmpeg encoding a film nobody was waiting for. The test caught a real bug on the way: two waiters could be let in for one slot, because a slot was counted when the waiter woke up rather than when it was given. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018H9CZxWumc3ryumgEHd578
Per-file cancel reached the coordinator, which cancels a task that is running. A row still waiting its turn has no task yet, so it was marked cancelled on screen and then converted anyway a moment later. The batch is told instead: the rows somebody stopped are asked about after the wait and before the work. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018H9CZxWumc3ryumgEHd578
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
One number decided how much ran at once, and it was wrong in both directions: two videos at a time is one too many, because the media engine is a single piece of hardware and asking it for two only makes heat, while two images at a time is far too few on a machine with ten cores.
The limit is now per kind of work, computed from the cores, the memory and whether this is Apple silicon — images bounded by memory, since a decoded photograph is a quarter of a gigabyte and eight at once is how a batch takes a Mac down. Nothing here decides which chip does the work: Core Image goes to the GPU, Vision to the neural engine, VideoToolbox to the media engine, and Apple routes that without being asked.
It backs off mid-batch: a warm Mac, Low Power Mode or memory pressure halves the limits or drops them to one, and they come back when the pressure does not. The screen says so rather than just getting slower.
Pause stops new files starting and lets the ones in flight finish — a native encode cannot be frozen halfway and a button claiming otherwise would be lying. Cancel now reaches one file as well as all of them, and reaches a subprocess: a cancelled conversion used to drop the task and leave ffmpeg encoding a film nobody was waiting for.
Two bugs the tests caught on the way: two waiters could be let in for one slot, because a slot was counted when the waiter woke up rather than when it was given; and stopping a row that had not started yet marked it cancelled on screen and converted it anyway.
Not built, deliberately: a software/high-quality encode toggle. AVFoundation exposes no software-encoder switch — VideoToolbox is already the default path and the quality choice is the export preset. A toggle that commutes nothing would be worse than none.
Test plan
swift test— green🤖 Generated with Claude Code
https://claude.ai/code/session_018H9CZxWumc3ryumgEHd578