-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: optimize worker system performance #851
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8a88f45
feat(cli): wrap entire defaultAction in child_process while optimizin…
yamadashy bd88340
refactor(cli): optimize defaultAction by moving config loading to mai…
yamadashy 681e377
refactor(shared): improve error handling and cleanup code
yamadashy 78b25b8
feat(core): use direct globby import instead of worker isolation
yamadashy 76dcbce
refactor(metrics): unify worker system with single TaskRunner lifecycle
yamadashy 8efeaf9
feat(cli): improve type safety and Bun compatibility in defaultAction…
yamadashy cd65912
fix(ci): add build step before tests to ensure worker files exist
yamadashy a85dd6b
refactor(test): eliminate build dependency by mocking worker logic di…
yamadashy e1be3df
refactor(metrics): simplify worker to token counter and move logic to…
yamadashy 1a8bca2
test(metrics): add comprehensive tests for worker functions
yamadashy 3266ad1
fix(test): make defaultActionWorker tests cross-platform compatible
yamadashy 7153526
fix(test): correct stdin processing path expectations in defaultActio…
yamadashy c106ca8
[autofix.ci] apply automated fixes
autofix-ci[bot] 5898d63
refactor(workers): improve code quality and type safety
yamadashy 1badf53
refactor(cli): optimize ping task and improve error handling
yamadashy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import path from 'node:path'; | ||
| import type { RepomixConfigMerged } from '../../../config/configSchema.js'; | ||
| import { readFilePathsFromStdin } from '../../../core/file/fileStdin.js'; | ||
| import { type PackResult, pack } from '../../../core/packager.js'; | ||
| import { RepomixError } from '../../../shared/errorHandle.js'; | ||
| import { logger, setLogLevelByWorkerData } from '../../../shared/logger.js'; | ||
| import { Spinner } from '../../cliSpinner.js'; | ||
| import type { CliOptions } from '../../types.js'; | ||
|
|
||
| // Initialize logger configuration from workerData at module load time | ||
| // This must be called before any logging operations in the worker | ||
| setLogLevelByWorkerData(); | ||
|
|
||
| export interface DefaultActionTask { | ||
| directories: string[]; | ||
| cwd: string; | ||
| config: RepomixConfigMerged; | ||
| cliOptions: CliOptions; | ||
| isStdin: boolean; | ||
| } | ||
|
|
||
| export interface PingTask { | ||
| ping: true; | ||
| } | ||
|
|
||
| export interface DefaultActionWorkerResult { | ||
| packResult: PackResult; | ||
| config: RepomixConfigMerged; | ||
| } | ||
|
|
||
| export interface PingResult { | ||
| ping: true; | ||
| } | ||
|
|
||
| // Function overloads for better type inference | ||
| function defaultActionWorker(task: DefaultActionTask): Promise<DefaultActionWorkerResult>; | ||
| function defaultActionWorker(task: PingTask): Promise<PingResult>; | ||
| async function defaultActionWorker( | ||
| task: DefaultActionTask | PingTask, | ||
| ): Promise<DefaultActionWorkerResult | PingResult> { | ||
|
yamadashy marked this conversation as resolved.
|
||
| // Handle ping requests for Bun compatibility check | ||
| if ('ping' in task) { | ||
| return { | ||
| ping: true, | ||
| }; | ||
| } | ||
|
|
||
| // At this point, task is guaranteed to be DefaultActionTask | ||
| const { directories, cwd, config, cliOptions, isStdin } = task; | ||
|
|
||
| logger.trace('Worker: Using pre-loaded config:', config); | ||
|
|
||
| // Initialize spinner in worker | ||
| const spinner = new Spinner('Initializing...', cliOptions); | ||
| spinner.start(); | ||
|
|
||
| let packResult: PackResult; | ||
|
|
||
| try { | ||
| if (isStdin) { | ||
| // Handle stdin processing | ||
| // Validate directory arguments for stdin mode | ||
| const firstDir = directories[0] ?? '.'; | ||
| if (directories.length > 1 || firstDir !== '.') { | ||
| throw new RepomixError( | ||
| 'When using --stdin, do not specify directory arguments. File paths will be read from stdin.', | ||
| ); | ||
| } | ||
|
|
||
| const stdinResult = await readFilePathsFromStdin(cwd); | ||
|
|
||
| // Use pack with predefined files from stdin | ||
| packResult = await pack( | ||
| [cwd], | ||
| config, | ||
| (message) => { | ||
| spinner.update(message); | ||
| }, | ||
| {}, | ||
| stdinResult.filePaths, | ||
| ); | ||
| } else { | ||
| // Handle directory processing | ||
| const targetPaths = directories.map((directory) => path.resolve(cwd, directory)); | ||
|
|
||
| packResult = await pack(targetPaths, config, (message) => { | ||
| spinner.update(message); | ||
| }); | ||
| } | ||
|
|
||
| spinner.succeed('Packing completed successfully!'); | ||
|
|
||
| return { | ||
| packResult, | ||
| config, | ||
| }; | ||
| } catch (error) { | ||
| spinner.fail('Error during packing'); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| export default defaultActionWorker; | ||
|
|
||
| // Export cleanup function for Tinypool teardown | ||
| export const onWorkerTermination = async () => { | ||
| // Any cleanup needed when worker terminates | ||
| // Currently no specific cleanup required for defaultAction worker | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.