Skip to content
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
merged 10 commits into from
May 1, 2024
Prev Previous commit
Next Next commit
chore: have uniqe ids for cache
  • Loading branch information
sheremet-va committed May 1, 2024
commit aa4b54a34c31ccd09594c23ade9a5903fb29a227
9 changes: 4 additions & 5 deletions packages/vitest/src/node/pools/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ export function createMethodsRPC(project: WorkspaceProject): RuntimeRPC {
if (!result.code && 'id' in result)
return result

if (!result.code) {
console.error(result)
return { code: `throw new Error('What is going on?')` }
}
if (!result.code)
throw new Error(`Failed to fetch module ${id}`)

const code = result.code
const dir = join(tmpdir(), transformMode)
const dir = join(tmpdir(), project.id, transformMode)
const tmp = join(dir, id.replace(/[/\\?%*:|"<>]/g, '_').replace('\0', '__x00__'))
if (promises.has(tmp)) {
await promises.get(tmp)
Expand Down
4 changes: 3 additions & 1 deletion packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { ViteNodeServer } from 'vite-node/server'
import c from 'picocolors'
import { createBrowserServer } from '../integrations/browser/server'
import type { ProvidedContext, ResolvedConfig, UserConfig, UserWorkspaceConfig, Vitest } from '../types'
import { deepMerge } from '../utils'
import type { Typechecker } from '../typecheck/typechecker'
import type { BrowserProvider } from '../types/browser'
import { getBrowserProvider } from '../integrations/browser'
import { deepMerge, nanoid } from '../utils/base'
import { isBrowserEnabled, resolveConfig } from './config'
import { WorkspaceVitestPlugin } from './plugins/workspace'
import { createViteServer } from './vite'
Expand Down Expand Up @@ -78,6 +78,8 @@ export class WorkspaceProject {

testFilesList: string[] | null = null

public readonly id = nanoid()

private _globalSetups: GlobalSetupFile[] | undefined
private _provided: ProvidedContext = {} as any

Expand Down
11 changes: 11 additions & 0 deletions packages/vitest/src/utils/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,14 @@ export function escapeRegExp(s: string) {
export function wildcardPatternToRegExp(pattern: string): RegExp {
return new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`, 'i')
}

// port from nanoid
// https://github.com/ai/nanoid
const urlAlphabet
= 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
export function nanoid(size = 21) {
let id = ''
let i = size
while (i--) id += urlAlphabet[(Math.random() * 64) | 0]
return id
}
19 changes: 15 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.