FranckFreiburger / vue3-sfc-loader

Single File Component loader for Vue2 and Vue3. Load .vue files directly from your HTML. No node.js environment, no build step.
MIT License
1.03k stars 116 forks source link

Slow parsing? #126

Closed webloft closed 5 months ago

webloft commented 2 years ago

First of all, great work!

But I tested the load-from-string example and the timing is just bad for production. It takes ~70ms to create the component from a simple string. I don't assume the problem is the content, since there is nothing great to parse.

So is it the invocation of the parser itself? Doing unnecessary steps or are the functions so big it takes so much time to load it? Can this be optimized?

const options = {
    moduleCache: {
        vue: Vue,
    },
    getFile() {
        return `<template>nothing</template>`
    },
    addStyle() { }
}

let begin = (new Date).getTime()
loadModule("foo.vue", options).then(() => {
    const elapsed = (new Date).getTime() - begin
    console.log("component created after " + elapsed + " ms")
})
FranckFreiburger commented 5 months ago

Hi webloft,

try to enable "compiledCache" :

const options = {
      ...
      compiledCache: {
        get: key => window.localStorage.getItem(key),
        set: (key, value) => window.localStorage.setItem(key, value),
      },
      ...
    }
FranckFreiburger commented 5 months ago

see also https://github.com/FranckFreiburger/vue3-sfc-loader/discussions/175