Nuxt.js: Import of nuxt is slow - 3 seconds for import -> speed it up somehow

Created on 2 Aug 2018  ·  12Comments  ·  Source: nuxt/nuxt.js

What problem does this feature solve?

It is pretty critical for serverless setups on lambda and so on.
https://nuxtjs.org/api/nuxt-render/

console.time('test')
const { Nuxt } = require('nuxt-edge')
console.timeEnd('test')
test: 2847.106ms

Its way too much to be 3sec for cold start

I tried to look why it take so long and 99% of time is spent on in nuxt-edge\dist\nuxt.js at the import section for that 50 imports section ..

There should be just a render function that dont have all that 50+ imports and other things that not really needed for rendering and used for building/debugging/etc

Nuxt 1 have like 0.5-1 second less import time, but still way too much, but nuxt-edge made it even worse

This feature request is available on Nuxt community (#c7483)
available soon feature-request

Most helpful comment

Hi @aldarund

Actually, when the app is built, it's better to use nuxt-start, until the package is published for 2.0, you can require it like so:

console.time('test')
const { Nuxt } = require('nuxt-edge/dist/nuxt-start')
console.timeEnd('test')
test: 208.735ms

When released, you will do:

const { Nuxt } = require('nuxt-start')

I'll keep it open until Nuxt 2.0 is out.

All 12 comments

Hi @aldarund

Actually, when the app is built, it's better to use nuxt-start, until the package is published for 2.0, you can require it like so:

console.time('test')
const { Nuxt } = require('nuxt-edge/dist/nuxt-start')
console.timeEnd('test')
test: 208.735ms

When released, you will do:

const { Nuxt } = require('nuxt-start')

I'll keep it open until Nuxt 2.0 is out.

It does not provide Builder.

import { Nuxt, Builder } from 'nuxt-edge/dist/nuxt-start'

It's normal since it's only runtime of Nuxt.js, no webpack, no babel, only Core, Modules and Renderer.

I summarized some time-consuming libs in Nuxt:

console.time('Time-consuming dependencies')
require('webpack')
require('webpack-bundle-analyzer');
require('uglifyjs-webpack-plugin');
require('@vue/component-compiler-utils')
require('html-minifier')
require('html-webpack-plugin')
console.timeEnd('Time-consuming dependencies')

console.time('Nuxt Core                  ')
require('nuxt-edge')
console.timeEnd('Nuxt Core                  ')

Output:
Time-consuming dependencies: 1560.845ms
Nuxt Core                  : 454.866ms

Majority of them have major release between Nuxt 1 and Nuxt-edge.

And the importing is more like a warming step, all imported modules will be cached, so I think it's reasonable to have this funcitonality.

@Atinux @pi0, do you think it's necessary to make them dynamic or lazy require in Nuxt, for example: require webpack inside Builder constructor or some where else inside function scope ?

I think its fine to have them as warmup with current time as long as render functionality can be imported and used separately ( from nuxt-start )
Is there a problem that reducing import time will solve ? It will make code complicated for what benefit?

I'm sorry I forgot that we have published nuxt-start-edge for only including Nuxt core functionality and reducing the time consuming.

https://www.npmjs.com/package/nuxt-edge-start

Which of those Time-consuming dependencies does nux-start require?
Because preloading them makes it go from 119.124ms to 68.404ms
I guess they have common dependencies on some smaller packages?

For me importing nuxt-start-edge takes 380-400ms
consola - 60ms
vue-server-renderer - 50ms
fs-extra - 52ms
serve-static - 40ms
esm - 46ms

Seems like we will have to load consola asynchronously 🤷‍♀️

The package has been released (as well as Nuxt 2)

This feature-request has been implemented by @Atinux.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  ·  3Comments

pehbehbeh picture pehbehbeh  ·  3Comments

msudgh picture msudgh  ·  3Comments

danieloprado picture danieloprado  ·  3Comments

gary149 picture gary149  ·  3Comments