-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
perf: improve performance of forks pool #5592
Merged
sheremet-va
merged 10 commits into
vitest-dev:main
from
sheremet-va:perf/make-forks-faster
May 1, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a3b9bc8
fix: report correct transform time
sheremet-va 1adaf88
perf: improve performance of forks pool
sheremet-va d025e9f
chore: udate list of invalid filename chars
sheremet-va d7a51a0
fix: replace null byte
sheremet-va aa4b54a
chore: have uniqe ids for cache
sheremet-va b1d6cbe
chore: fix web-worker fetchModule
sheremet-va 9a85f4d
fix: introduce fetchResult method in vite-node
sheremet-va a37287f
chore: read file async
sheremet-va 006e0a5
fix: don't send map
sheremet-va f5e4ebf
chore: keep code
sheremet-va 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 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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { mkdir, writeFile } from 'node:fs/promises' | ||
import type { RawSourceMap } from 'vite-node' | ||
import { join } from 'pathe' | ||
import type { RuntimeRPC } from '../../types' | ||
import type { WorkspaceProject } from '../workspace' | ||
|
||
const created = new Set() | ||
const promises = new Map<string, Promise<void>>() | ||
|
||
export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC { | ||
const ctx = project.ctx | ||
return { | ||
|
@@ -20,8 +25,31 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC { | |
const r = await project.vitenode.transformRequest(id) | ||
return r?.map as RawSourceMap | undefined | ||
}, | ||
fetch(id, transformMode) { | ||
return project.vitenode.fetchModule(id, transformMode) | ||
async fetch(id, transformMode) { | ||
AriPerkkio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result = await project.vitenode.fetchResult(id, transformMode) | ||
const code = result.code | ||
if (result.externalize) | ||
return result | ||
if ('id' in result) | ||
return { id: result.id as string } | ||
|
||
if (!code) | ||
throw new Error(`Failed to fetch module ${id}`) | ||
|
||
const dir = join(project.tmpDir, transformMode) | ||
const tmp = join(dir, id.replace(/[/\\?%*:|"<>]/g, '_').replace('\0', '__x00__')) | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is causing too long filenames: https://github.com/vitest-dev/vitest-ecosystem-ci/actions/runs/8911833491/job/24473995666
|
||
if (promises.has(tmp)) { | ||
await promises.get(tmp) | ||
return { id: tmp } | ||
} | ||
if (!created.has(dir)) { | ||
await mkdir(dir, { recursive: true }) | ||
created.add(dir) | ||
} | ||
promises.set(tmp, writeFile(tmp, code, 'utf-8').finally(() => promises.delete(tmp))) | ||
await promises.get(tmp) | ||
Object.assign(result, { id: tmp }) | ||
return { id: tmp } | ||
AriPerkkio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
resolveId(id, importer, transformMode) { | ||
return project.vitenode.resolveId(id, importer, transformMode) | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why using sync IO in async context? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it’s faster. we rarely import multiple modules at the same time, so nothing is executed in parallel most of the time