File tree Expand file tree Collapse file tree 11 files changed +71
-3
lines changed
website/src/latest/api/cli Expand file tree Collapse file tree 11 files changed +71
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @callstack/repack " : minor
3+ ---
4+
5+ Add ` --max-workers ` option to start & bundle commands. By default the number of workers is derived from available cores. This option is only effective for Rspack configurations
Original file line number Diff line number Diff line change 1+ import os from 'node:os' ;
2+
3+ export function getMaxWorkers ( ) : number {
4+ const cores = os . availableParallelism ( ) ;
5+
6+ const decayCoefficient = 0.07 ;
7+ const decay = Math . exp ( - cores * decayCoefficient ) ;
8+
9+ // Scale transitions from 1.0 (low cores) toward 0.5 (many cores)
10+ const scale = 0.5 + 0.5 * decay ;
11+
12+ // Adjust down slightly to leave headroom for main thread and I/O
13+ const adjusted = cores * scale - 1 ;
14+
15+ return Math . max ( 1 , Math . ceil ( adjusted ) ) ;
16+ }
Original file line number Diff line number Diff line change 11export * from './getDevMiddleware.js' ;
2+ export * from './getMaxWorkers.js' ;
23export * from './getMimeType.js' ;
34export * from './parseUrl.js' ;
45export * from './resetPersistentCache.js' ;
Original file line number Diff line number Diff line change 11import {
22 ASSETS_DEST_ENV_KEY ,
33 BUNDLE_FILENAME_ENV_KEY ,
4+ RSPACK_RAYON_THREADS_ENV_KEY ,
5+ RSPACK_TOKIO_THREADS_ENV_KEY ,
46 SOURCEMAP_FILENAME_ENV_KEY ,
57 VERBOSE_ENV_KEY ,
68} from '../../env.js' ;
@@ -24,3 +26,8 @@ export function setupEnvironment(args: EnvironmentArgs): void {
2426 setEnvVar ( SOURCEMAP_FILENAME_ENV_KEY , args . sourcemapOutput ) ;
2527 setEnvVar ( ASSETS_DEST_ENV_KEY , args . assetsDest ) ;
2628}
29+
30+ export function setupRspackEnvironment ( maxWorkers : string ) : void {
31+ setEnvVar ( RSPACK_TOKIO_THREADS_ENV_KEY , maxWorkers ) ;
32+ setEnvVar ( RSPACK_RAYON_THREADS_ENV_KEY , maxWorkers ) ;
33+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ export const startCommandOptions = [
5959 name : '--verbose' ,
6060 description : 'Enables verbose logging' ,
6161 } ,
62+ {
63+ name : '--max-workers <number>' ,
64+ description :
65+ '(Rspack only) The maximum number of workers to use for transformation parallelization ' ,
66+ parse : ( val : string ) => Number ( val ) ,
67+ } ,
6268 {
6369 name : '--config <path>' ,
6470 description : 'Path to a bundler config file, e.g webpack.config.js' ,
@@ -149,6 +155,12 @@ export const bundleCommandOptions = [
149155 name : '--watch' ,
150156 description : 'Watch for file changes' ,
151157 } ,
158+ {
159+ name : '--max-workers <number>' ,
160+ description :
161+ '(Rspack only) The maximum number of workers to use for transformation parallelization ' ,
162+ parse : ( val : string ) => Number ( val ) ,
163+ } ,
152164 {
153165 name : '--config <path>' ,
154166 description : 'Path to a bundler config file, e.g webpack.config.js' ,
Original file line number Diff line number Diff line change @@ -3,11 +3,13 @@ import type { Stats } from '@rspack/core';
33import { CLIError } from '../../helpers/index.js' ;
44import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js' ;
55import {
6+ getMaxWorkers ,
67 normalizeStatsOptions ,
78 resetPersistentCache ,
9+ setupEnvironment ,
10+ setupRspackEnvironment ,
811 writeStats ,
912} from '../common/index.js' ;
10- import { setupEnvironment } from '../common/setupEnvironment.js' ;
1113import type { BundleArguments , CliConfig } from '../types.js' ;
1214
1315/**
@@ -35,6 +37,9 @@ export async function bundle(
3537 // expose selected args as environment variables
3638 setupEnvironment ( args ) ;
3739
40+ const maxWorkers = args . maxWorkers ?? getMaxWorkers ( ) ;
41+ setupRspackEnvironment ( maxWorkers . toString ( ) ) ;
42+
3843 if ( ! args . entryFile && ! config . entry ) {
3944 throw new CLIError ( "Option '--entry-file <path>' argument is missing" ) ;
4045 }
Original file line number Diff line number Diff line change @@ -12,15 +12,17 @@ import {
1212import { makeCompilerConfig } from '../common/config/makeCompilerConfig.js' ;
1313import {
1414 getDevMiddleware ,
15+ getMaxWorkers ,
1516 getMimeType ,
1617 parseUrl ,
1718 resetPersistentCache ,
1819 resolveProjectPath ,
20+ runAdbReverse ,
21+ setupEnvironment ,
1922 setupInteractions ,
23+ setupRspackEnvironment ,
2024} from '../common/index.js' ;
21- import { runAdbReverse } from '../common/index.js' ;
2225import logo from '../common/logo.js' ;
23- import { setupEnvironment } from '../common/setupEnvironment.js' ;
2426import type { CliConfig , StartArguments } from '../types.js' ;
2527import { Compiler } from './Compiler.js' ;
2628
@@ -58,6 +60,9 @@ export async function start(
5860 // expose selected args as environment variables
5961 setupEnvironment ( args ) ;
6062
63+ const maxWorkers = args . maxWorkers ?? getMaxWorkers ( ) ;
64+ setupRspackEnvironment ( maxWorkers . toString ( ) ) ;
65+
6166 const isVerbose = isTruthyEnv ( process . env [ VERBOSE_ENV_KEY ] ) ;
6267 const devServerOptions = configs [ 0 ] . devServer ?? { } ;
6368 const showHttpRequests = isVerbose || args . logRequests ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export interface BundleArguments {
1313 resetCache ?: boolean ;
1414 verbose ?: boolean ;
1515 watch ?: boolean ;
16+ maxWorkers ?: number ;
1617 config ?: string ;
1718 webpackConfig ?: string ;
1819}
@@ -31,6 +32,7 @@ export interface StartArguments {
3132 resetCache ?: boolean ;
3233 reversePort ?: boolean ;
3334 verbose ?: boolean ;
35+ maxWorkers ?: number ;
3436 config ?: string ;
3537 webpackConfig ?: string ;
3638}
Original file line number Diff line number Diff line change @@ -5,4 +5,7 @@ export const BUNDLE_FILENAME_ENV_KEY = 'REPACK_BUNDLE_FILENAME';
55export const SOURCEMAP_FILENAME_ENV_KEY = 'REPACK_SOURCEMAP_FILENAME' ;
66export const ASSETS_DEST_ENV_KEY = 'REPACK_ASSETS_DEST' ;
77
8+ export const RSPACK_TOKIO_THREADS_ENV_KEY = 'TOKIO_WORKER_THREADS' ;
9+ export const RSPACK_RAYON_THREADS_ENV_KEY = 'RAYON_NUM_THREADS' ;
10+
811export const EXPERIMENTAL_CACHE_ENV_KEY = 'REPACK_EXPERIMENTAL_CACHE' ;
Original file line number Diff line number Diff line change @@ -120,6 +120,12 @@ Enables verbose logging.
120120
121121Watch for file changes.
122122
123+ ### ` --max-workers `
124+
125+ - Type: ` number `
126+
127+ (Rspack only) The maximum number of workers to use for transformation parallelization. By default, the number of workers is derived from available CPU cores.
128+
123129### ` --config `
124130
125131- Type: ` string `
You can’t perform that action at this time.
0 commit comments