Skip to content
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

Fix setting of common properties (-mmt=n option is ignored by many handlers) #349

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

sebres
Copy link
Collaborator

@sebres sebres commented Aug 31, 2023

This PR fixes setting of -mmt=n option for many handlers (previously ignored by zstd, brotli, lz*, etc), so adding -mmt=1 to the call like below caused multi-threaded processing with default number of threads:

7z a -tzstd -mmt=1 archive.zstd large-file-to-compress.txt

So parallel compression of multiple files with several processes can cause unneeded context switches due to unexpected multi-threaded processing.

Analyze

Return after call of SetCommonProperty (setting common properties mt and memuse to members of CCommonMethodProps avoid that properties gets added regularly, so many handlers setting that via SetCoderProperties wouldn't consider that option at all, because option doesn't exists in the props.
For example this branch was previously never reachable:

case NCoderPropID::kNumThreads:

Alternatively one'd rewrite it in every affected handler like in:

static HRESULT UpdateArchive(

with:

 static HRESULT UpdateArchive(
     UInt64 unpackSize,
     ISequentialOutStream *outStream,
-    const CProps &props,
+    const CSingleMethodProps &props,
 ...
   RINOK(props.SetCoderProps(encoderSpec, NULL));
+  if (props._numThreads_WasForced) {
+    encoderSpec->SetNumberOfThreads(props._numThreads);
+  }

Just it would be not quite backwards compatible (if one remove dup processing in SetCoderProperties at the same time).
As well as one should extend encoder and/or decoder of every handler, and this fix is minimalistic in opposite.

…s used SetCoderProperties to set number of threads)
@mcmilk
Copy link
Owner

mcmilk commented Sep 6, 2023

Thank you.

@mcmilk mcmilk closed this Sep 6, 2023
Copy link
Owner

@mcmilk mcmilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@mcmilk mcmilk reopened this Sep 6, 2023
@mcmilk mcmilk merged commit 3de9e01 into mcmilk:master Sep 6, 2023
9 checks passed
@sebres sebres deleted the fix-set-common-props branch September 6, 2023 18:03
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.

2 participants