-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): parallel file parsing (#6382)
This PR enables parallel parsing of files, utilizing multiple parser workers. Until now we had only one `ParserPrinterWorker`, which had to handle parsing all of the files serially. In our sample store this could be ~10-15s spent only on parsing (depending on the machine). In this PR we're introducting the ability to spin multiple workers, and divide the file load between them, allowing the parsing to be parallel. **Note to reviewers:** Main logic changes are in `worker-types.ts` and `workers.ts` Some important points: 1. Since parsing the files happens on the load critical path, we can easily hit a hardware limitation due to multiple workers/main thread that take up all the processes. This limits us both in the number of new workers we can spin up, and also causing N workers to work for more that 1/N of the time in parallel. Even though - there are still meaningful gains. 2. There is an overhead to spinning up workers, since our parsing code itself is heavy and takes some time to evaluate. A proper threadpool solution might be able to solve that (spin workers when needed and keep them alive as long as the parse load is large). However this requires changing our entire worker mechansim, and can even hurt performance since spinning up new workers in the "middle" of the parsing flow creates an overhead. However this can be a future optimization - to start with 3-4 workers in advance and if needed spin up more using a threadpool library (`workerspool` or `threads`, for example). 3. Our current chunking algorithm splits the parsable files (not all files are parsable) into N chunks that are more-or-less equal in terms of the sum of their file length, and sends them in parallel to N workers. This makes sure that all of the workers will work for roughly the same amount of time. A proper threadpool queue-based solution could be more efficient here (since it will always send the next file to an available worker) but the difference to the current "naive" chunking implementation wouldn't be that large, and it will also add a small messaging overhead (sending each file in turn). 4. The current concurrency is 3, and this will be configurable from the settings/RYO menu after #6381 will be merged. **Commit Details:** - Added support for multiple parse workers in `UtopiaTsWorkers` - Changed `getParseResult` to chunk the files, and call on each chunk `getParseResultSerial`, waiting for all of them to return before returning the result - `getParseResultSerial` now looks for the next available `ParserPrinterWorker` to send the next chunk to, for parsing - Worker code itself remained unchanged - The feature can be toggles on/off from the settings menu **Manual Tests:** I hereby swear that: - [X] I opened a hydrogen project and it loaded - [X] I could navigate to various routes in Preview mode Fixes #5655
- Loading branch information
Showing
17 changed files
with
299 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
7 changes: 2 additions & 5 deletions
7
editor/src/components/editor/store/editor-dispatch-performance-logging.tsx
This file contains 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 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 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 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 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 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 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 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 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,23 @@ | ||
import { isFeatureEnabled } from '../../../utils/feature-switches' | ||
|
||
// TODO: this will be configurable from the RYO menu | ||
export const PARSE_CONCURRENCY = 3 | ||
const PARSER_CONCURRENCY_FEATURE = 'Parallel Parsing' | ||
const LOG_CONCURRENCY_TIMINGS_FEATURE = 'Log Parse Timings' | ||
|
||
export function isConcurrencyEnabled() { | ||
return isFeatureEnabled(PARSER_CONCURRENCY_FEATURE) | ||
} | ||
|
||
export function getParserWorkerCount() { | ||
return isConcurrencyEnabled() ? PARSE_CONCURRENCY : 1 | ||
} | ||
|
||
export function getParserChunkCount() { | ||
return isConcurrencyEnabled() ? PARSE_CONCURRENCY : 1 | ||
} | ||
|
||
// TODO: this will be configurable from the RYO menu | ||
export function isConcurrencyLoggingEnabled() { | ||
return isFeatureEnabled(LOG_CONCURRENCY_TIMINGS_FEATURE) | ||
} |
Oops, something went wrong.