Improve seekable_format/examples/parallel_compression #4382
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.
Change the design of parallel_compression, to allow it to actually work in parallel without blowing up memory usage. Fixes #3980.
In the new approach, we don't wait for all jobs to be accepted by the queue before writing any results. Instead, as each job finishes, it adds its result to an ordered-linked-list, and then writes (and frees) as many results as are available. We use a mutex for synchronization, so this should no longer be racy. This approach also conveniently allows streaming input, since we no longer need to know the number of frames ahead of time.
An added test enforces that parallel_compression doesn't use excessive memory.
This doesn't change anything about the main zstd program, so we should leave #3980 open, or open a new issue about zstd CLI seekability.
A variety of other fixes were necessary to get test passing, or were obvious cleanups once this was complete. Each is a separate commit.