evidence icon indicating copy to clipboard operation
evidence copied to clipboard

Faster Dev Server Boot

Open mcrascal opened this issue 2 years ago • 7 comments

npm run dev takes a lot longer to get to a live app than a bare sveltekit app does. In addition to #922, improving this would do a lot for the initial experience of trying out evidence, and for my own day to day experience of using it.

mcrascal avatar Feb 05 '24 22:02 mcrascal

Some profiling suggests a major cause is large files in dependencies taking up a lot of time in a vite function called ssrTransformScript (~4.1s). Main perpetrators:

image image image

There's a few other fat time sinks like svelte file compilation (~1.7s) - 170 files are compiled when the dev server is started, so we should figure out if there's a way to avoid that.

csjh avatar Feb 23 '24 00:02 csjh

Can't actually see these images, Non-Image content-type returned but I assume they are inadvertent additions?

archiewood avatar Feb 23 '24 00:02 archiewood

Whoops, updated

csjh avatar Feb 23 '24 01:02 csjh

I'm looking through vite config for something else and stumbled upon this warmup option - sharing in case it's useful here: https://vitejs.dev/config/server-options.html#server-warmup

hughess avatar Feb 23 '24 15:02 hughess

Yeah seems like that helps move the heavy bits to the start of the dev server instead of later in, but the end result is the same

csjh avatar Feb 23 '24 18:02 csjh

@csjh what was your rough profiling setup to get these measurements?

archiewood avatar Mar 05 '24 21:03 archiewood

@archiewood I've been modifying node_modules/vite/bin/vite.js because their --profile flag wasn't working 100% correctly for me

Basically just go in that file and replace

  session.post('Profiler.enable', () => {
    session.post('Profiler.start', start)
  })

(located near the bottom) with

  session.post('Profiler.enable', () => {
    session.post('Profiler.start', start)
	setTimeout(() => {
		session.post('Profiler.stop', async (err, { profile }) => {
			if (err) {
				console.error(err)
				process.exit(1)
			}
			const fs = await import('node:fs')
			const path = await import('node:path')
			const filename = path.resolve(process.cwd(), 'v8-profile.cpuprofile')
			fs.writeFileSync(filename, JSON.stringify(profile))
			console.log(`Profile written to ${filename}`)
			process.exit(0)
		})
	}, 20000);
  })

and run vite with the --profile flag after the .cpuprofile can be loaded into chrome

csjh avatar Mar 05 '24 21:03 csjh