Skip to content

Commit

Permalink
Perf: run cpu intensive task with worker
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Sep 14, 2023
1 parent b42bd05 commit 9fa9ded
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 7 deletions.
30 changes: 29 additions & 1 deletion Build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,42 @@ const { buildTelegramCIDR } = require('./build-telegram-cidr');
const { buildChnCidr } = require('./build-chn-cidr');
const { buildSpeedtestDomainSet } = require('./build-speedtest-domainset');
const { buildInternalCDNDomains } = require('./build-internal-cdn-rules');
const { buildInternalReverseChnCIDR } = require('./build-internal-reverse-chn-cidr');
const { buildInternalChnDomains } = require('./build-internal-chn-domains');
const { buildDomesticRuleset } = require('./build-domestic-ruleset');
const { validate } = require('./validate-domainset');

const { buildPublicHtml } = require('./build-public');

const { Worker } = require('jest-worker');

/**
* @template T
* @typedef {import('jest-worker').Worker & T} WithWorker
*/

/**
* @template T
* @param {string} path
* @returns {WithWorker<T>}
*/
const requireWorker = (path) => {
const _worker = (new Worker(
require.resolve(path),
{
numWorkers: 1,
maxRetries: 0,
enableWorkerThreads: true
}
));
_worker.getStderr().pipe(process.stderr);
_worker.getStdout().pipe(process.stdout);

return _worker;
};

(async () => {
const { buildInternalReverseChnCIDR } = /** @type {WithWorker<import('./build-internal-reverse-chn-cidr')>} */ (requireWorker('./build-internal-reverse-chn-cidr'));

// download-previous-build
const downloadPreviousBuildPromise = downloadPreviousBuild();
const downloadPublicSuffixListPromise = downloadPublicSuffixList();
Expand Down
4 changes: 2 additions & 2 deletions Build/lib/is-domain-loose.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports.isDomainLoose = (domain) => {
};

/**
* @param {string} domain
* @param {string | null | undefined} domain
*/
module.exports.normalizeDomain = (domain) => {
if (domain == null) {
if (!domain) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"cidr-tools-wasm": "^0.0.11",
"fs-extra": "^11.1.1",
"gorhill-publicsuffixlist": "github:gorhill/publicsuffixlist.js",
"jest-worker": "^29.7.0",
"mnemonist": "^0.39.5",
"path-scurry": "^1.10.1",
"picocolors": "^1.0.0",
Expand Down
82 changes: 78 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9fa9ded

Please sign in to comment.