Skip to content

Commit

Permalink
Perf: avoid iterate domainSets twice
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jul 21, 2024
1 parent 9d47cb9 commit 26a4d72
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Build/build-reject-domainset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,37 @@ export const buildRejectDomainSet = task(import.meta.main, import.meta.path)(asy
return domainKeywordsSet;
});

const [baseTrie, extraTrie] = span.traceChildSync('create smol trie while deduping black keywords', () => {
const [baseTrie, extraTrie] = span.traceChildSync('create smol trie while deduping black keywords', (childSpan) => {
const baseTrie = createTrie(null, true, true);
const extraTrie = createTrie(null, true, true);

const kwfilter = createKeywordFilter(domainKeywordsSet);

for (const domain of domainSets) {
// exclude keyword when creating trie
if (!kwfilter(domain)) {
baseTrie.add(domain);
childSpan.traceChildSync('add items to trie (extra)', () => {
for (const domain of domainSetsExtra) {
// exclude keyword when creating trie
if (!kwfilter(domain)) {
extraTrie.add(domain);
}
}
}
});

childSpan.traceChildSync('add items to trie (base) + dedupe extra trie', () => {
for (const domain of domainSets) {
// exclude keyword when creating trie
if (!kwfilter(domain)) {
baseTrie.add(domain);

for (const domain of domainSetsExtra) {
// exclude keyword when creating trie
if (!kwfilter(domain)) {
extraTrie.add(domain);
extraTrie.whitelist(domain);
}
}
}
});

return [baseTrie, extraTrie] as const;
});

span.traceChildSync('dedupe from white suffixes (base)', () => filterRuleWhitelistDomainSets.forEach(baseTrie.whitelist));
span.traceChildSync('dedupe from white suffixes and base (extra)', () => {
domainSets.forEach(extraTrie.whitelist);
filterRuleWhitelistDomainSets.forEach(extraTrie.whitelist);
});

Expand Down

0 comments on commit 26a4d72

Please sign in to comment.