Skip to content

Commit

Permalink
feat(config): collectMaxThreads
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Dec 19, 2022
1 parent 7c2133d commit 5008ecb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
12 changes: 12 additions & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,15 @@ export default defineConfig({
],
})
```

## `collectMaxThreads`

`number` - Default: available cpus

Number of maximum threads used to collect stories (both for development and building). Threads count will never go above this limit but might be lower.

```ts
export default defineConfig({
collectMaxThreads: 4,
})
```
5 changes: 5 additions & 0 deletions packages/histoire-shared/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export interface HistoireConfig {
*/
web?: RegExp[]
}
/**
* Maximum number of threads used to collect stories.
* By default based on available number of cores.
*/
collectMaxThreads?: number
}

export type ConfigMode = 'build' | 'dev'
6 changes: 4 additions & 2 deletions packages/histoire/src/node/collect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export function useCollectStories (options: UseCollectStoriesOptions, ctx: Conte
transformMode: ctx.config.viteNodeTransformMode,
})

const maxThreads = ctx.config.collectMaxThreads ?? cpus().length

const threadsCount = ctx.mode === 'dev'
? Math.max(cpus().length / 2, 1)
: Math.max(cpus().length - 1, 1)
? Math.max(Math.min(maxThreads, cpus().length / 2), 1)
: Math.max(Math.min(maxThreads, cpus().length - 1), 1)
console.log(pc.blue(`Using ${threadsCount} threads for story collection`))

const threadPool = new Tinypool({
Expand Down

0 comments on commit 5008ecb

Please sign in to comment.