Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Keep the decimal part of `concurrency` percentages

serdarucelfaa5e2bf6ffe
diff --git a/packages/renderer/src/get-concurrency.ts b/packages/renderer/src/get-concurrency.ts
index b66ef111d9..5336a5c92e 100644
--- a/packages/renderer/src/get-concurrency.ts
+++ b/packages/renderer/src/get-concurrency.ts
@@ -11,7 +11,7 @@ export const resolveConcurrency = (userPreference: number | string | null) => {
let rounded;
if (typeof userPreference === 'string') {
- const percentage = parseInt(userPreference.slice(0, -1), 10);
+ const percentage = parseFloat(userPreference.slice(0, -1));
rounded = Math.floor((percentage / 100) * maxCpus);
} else {
rounded = Math.floor(userPreference);
diff --git a/packages/renderer/src/test/actual-concurrency.test.ts b/packages/renderer/src/test/actual-concurrency.test.ts
index 8a3ca03aed..5718a76762 100644
--- a/packages/renderer/src/test/actual-concurrency.test.ts
+++ b/packages/renderer/src/test/actual-concurrency.test.ts
@@ -27,3 +27,30 @@ test('Slightly over 100% is ok as long as it is rounded', () => {
test('Should also accept integers', () => {
expect(resolveConcurrency(1)).toBe(1);
});
+
+test.skipIf((getCpuCount() as number) < 2)(
+ '62.5% should be 5/8 of the cores',
+ () => {
+ expect(resolveConcurrency('62.5%')).toBe(
+ Math.floor((getCpuCount() as number) * 0.625),
+ );
+ },
+);
+
+test.skipIf((getCpuCount() as number) < 2)(
+ '87.5% should be 7/8 of the cores',
+ () => {
+ expect(resolveConcurrency('87.5%')).toBe(
+ Math.floor((getCpuCount() as number) * 0.875),
+ );
+ },
+);
+
+test.skipIf((getCpuCount() as number) < 8)(
+ '12.5% should be 1/8 of the cores',
+ () => {
+ expect(resolveConcurrency('12.5%')).toBe(
+ Math.floor((getCpuCount() as number) * 0.125),
+ );
+ },
+);