瀏覽代碼

Perf: improve reject set dedupe performance

SukkaW 3 年之前
父節點
當前提交
a08bc60052
共有 2 個文件被更改,包括 11 次插入7 次删除
  1. 1 1
      Build/build-reject-domainset.js
  2. 10 6
      Build/worker/build-reject-domainset-worker.js

+ 1 - 1
Build/build-reject-domainset.js

@@ -150,7 +150,7 @@ const threads = require('os').cpus().length - 1;
 
   const piscina = new Piscina({
     filename: pathResolve(__dirname, 'worker/build-reject-domainset-worker.js'),
-    workerData: domainSets
+    workerData: [...domainSets]
   });
 
   (await Promise.all([

+ 10 - 6
Build/worker/build-reject-domainset-worker.js

@@ -1,21 +1,25 @@
 const { workerData } = require('piscina');
 
+const len = workerData.length;
+
 exports.dedupe = ({ chunk }) => {
   const outputToBeRemoved = new Set();
 
   for (let i = 0, l = chunk.length; i < l; i++) {
     const domainFromInput = chunk[i];
-    for (const domainFromFullSet of workerData) {
-      if (outputToBeRemoved.has(domainFromFullSet)) continue;
+
+    for (let j = 0; j < len; j++) {
+      const domainFromFullSet = workerData[j];
+
       if (domainFromFullSet === domainFromInput) continue;
-      if (domainFromFullSet.charAt(0) !== '.') continue;
+      if (domainFromFullSet.charCodeAt(0) !== 46) continue;
       // domainFromFullSet is now startsWith a "."
 
-      if (domainFromInput.charAt(0) !== '.') {
+      if (domainFromInput.charCodeAt(0) !== 46) {
         let shouldBeRemoved = true;
 
-        for (let j = 0, l2 = domainFromInput.length; j < l2; j++) {
-          if (domainFromFullSet.charAt(j + 1) !== domainFromInput.charAt(j)) {
+        for (let k = 0, l2 = domainFromInput.length; k < l2; k++) {
+          if (domainFromFullSet.charCodeAt(k + 1) !== domainFromInput.charCodeAt(k)) {
             shouldBeRemoved = false;
             break;
           }