Code Monkey home page Code Monkey logo

Comments (10)

Knagis avatar Knagis commented on June 1, 2024 2

And changing

let unpack = require('caniuse-lite').feature

to

let unpack = require('caniuse-lite/dist/unpacker/feature');

results in total time of 100ms.

So without any caching, these two imports reduce startup time from ~300ms to ~100ms.

from autoprefixer.

ai avatar ai commented on June 1, 2024

in-memory cache to disk to avoid this

require() should already have this cache. require() the module next time took less time (if there is no hacks around require()).

How do you plan to add better cache?

from autoprefixer.

Knagis avatar Knagis commented on June 1, 2024

i want the cache to be persisted between compilation runs. so restarting compilation process would be slightly faster. it can also thus be shared between different processes (like production webpack runs and storybook builds etc.)

from autoprefixer.

Knagis avatar Knagis commented on June 1, 2024
const started = Date.now();
let { agents } = require('caniuse-lite')
let dataPrefixes = require('../data/prefixes')
console.log("caniuse require took", (Date.now() - started), "ms");

Running node node_modules\autoprefixer\lib\autoprefixer.js (node 16.19.0):

caniuse require took 423 ms
caniuse require took 327 ms
caniuse require took 324 ms
caniuse require took 320 ms
caniuse require took 331 ms
caniuse require took 334 ms
caniuse require took 338 ms

from autoprefixer.

ai avatar ai commented on June 1, 2024

Yes, I understand the problem (honestly, it mostly came from ts-node because it parses all require files, and Can I Use DB has a big JSONs).

What solution do you suggest?

from autoprefixer.

Knagis avatar Knagis commented on June 1, 2024

the times above are plain node, without ts-node.

The let autoprefixerData = { browsers: agents, prefixes: dataPrefixes } object serialized to JSON takes around 285KB in my case. So I was thinking of writing this to disk (probably, just based on caniuse-lite/package.json version) and reading when available.

from autoprefixer.

Knagis avatar Knagis commented on June 1, 2024

First small thing - changing

let { agents } = require('caniuse-lite')

to

let { agents } = require('caniuse-lite/dist/unpacker/agents')

removes the big cost to load whole caniuse-lite for loading just browser stats - this same import is used by browserslist to calculate usage.

So that leaves only the feature require.

from autoprefixer.

ai avatar ai commented on June 1, 2024

So I was thinking of writing this to disk (probably, just based on caniuse-lite/package.json version) and reading when available

You need to think about cache invalidation on caniuse-lite update. And about working in the environment without fs (for instance, in the browser).

It could be much more complex, than you think.

let { agents } = require('caniuse-lite/dist/unpacker/agents')

Yes, we can change it. Send PR.

from autoprefixer.

Knagis avatar Knagis commented on June 1, 2024

PR incoming.

from autoprefixer.

ai avatar ai commented on June 1, 2024

The fix was released in 10.4.14.

from autoprefixer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.