Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run prebuild pages in parallel #126

Open
StarpTech opened this issue Apr 4, 2019 · 0 comments
Open

Run prebuild pages in parallel #126

StarpTech opened this issue Apr 4, 2019 · 0 comments

Comments

@StarpTech
Copy link

StarpTech commented Apr 4, 2019

Currently, I see no benefit to run the builds (pages) sequential. We can improve the performance by a factor of 5x if we run them in parallel. Or do I miss something?

Example

prebuild-worker.js

'use strict';

const { run } = require('@marko/prebuild');
const lassoConfig = require('./src/lasso-config');

async function prebuild(path) {
  await run({
    config: lassoConfig, // Either a lasso config object, or a path to one.
    flags: [], // Lasso flags to use when building the pages.
    pages: [path]
  });
}

prebuild(process.argv[2]).catch(err => {
  throw err;
});

prebuild.js

'use strict';

const globby = require('globby');
const execa = require('execa');

async function prebuild() {
  const ops = (await globby(['src/pages/*/*.marko'])).map(path =>
    execa('node', ['prebuild-worker.js', path])
  );
  await Promise.all(ops);
  // All templates have their prebuild.json files written to disk.
  console.log(`Prebuild completed!`);
}

prebuild().catch(err => {
  throw err;
});

Benchmark

CPU: AMD Ryzen 5 2600X (12) @ 3.600G
SSD

12 pages, 30 components with sass, babel, minifying, bundling

~80sec
~17sec with the solution above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant