Open mcrascal opened 5 months ago
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:
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.
Can't actually see these images, Non-Image content-type returned
but I assume they are inadvertent additions?
Whoops, updated
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
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 what was your rough profiling setup to get these measurements?
@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
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.