diff --git a/Build/build-internal-cdn-rules.ts b/Build/build-internal-cdn-rules.ts index 720f3350..adb26e13 100644 --- a/Build/build-internal-cdn-rules.ts +++ b/Build/build-internal-cdn-rules.ts @@ -53,7 +53,7 @@ export const buildInternalCDNDomains = task(import.meta.path, async () => { addApexDomain(line.replace('DOMAIN,', '')); } else if (line.startsWith('DOMAIN-KEYWORD')) { keywords.add(escapeRegExp(line.replace('DOMAIN-KEYWORD,', ''))); - } else if (line.startsWith('USER-AGENT,') || line.startsWith('PROCESS-NAME,')) { + } else if (line.startsWith('USER-AGENT,') || line.startsWith('PROCESS-NAME,') || line.startsWith('URL-REGEX,')) { // do nothing } else if (processLine(line)) { console.warn('[drop line from ruleset]', line); diff --git a/Build/lib/create-file.ts b/Build/lib/create-file.ts index c6360216..fd86c7ee 100644 --- a/Build/lib/create-file.ts +++ b/Build/lib/create-file.ts @@ -21,7 +21,7 @@ export async function compareAndWriteFile(linesA: string[], filePath: string) { const lineA = linesA[index]; index++; - if (lineA === undefined) { + if (typeof lineA !== 'string') { // The file becomes smaller isEqual = false; break; diff --git a/Build/lib/parse-filter.ts b/Build/lib/parse-filter.ts index 6817f827..c8695b6e 100644 --- a/Build/lib/parse-filter.ts +++ b/Build/lib/parse-filter.ts @@ -4,7 +4,6 @@ import * as tldts from './cached-tld-parse'; import { fetchRemoteTextAndCreateReadlineInterface } from './fetch-remote-text-by-line'; import { NetworkFilter } from '@cliqz/adblocker'; import { processLine } from './process-line'; -import { performance } from 'perf_hooks'; import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix'; import type { PublicSuffixList } from 'gorhill-publicsuffixlist'; @@ -104,7 +103,7 @@ export async function processFilterRules( filterRulesUrl: string | URL, fallbackUrls?: ReadonlyArray | undefined ): Promise<{ white: Set, black: Set, foundDebugDomain: boolean }> { - const runStart = performance.now(); + const runStart = Bun.nanoseconds(); const whitelistDomainSets = new Set(); const blacklistDomainSets = new Set(); @@ -174,10 +173,10 @@ export async function processFilterRules( if (!fallbackUrls || fallbackUrls.length === 0) { downloadTime = 0; - let last = performance.now(); + let last = Bun.nanoseconds(); for await (const line of await fetchRemoteTextAndCreateReadlineInterface(filterRulesUrl)) { - const now = performance.now(); - downloadTime += performance.now() - last; + const now = Bun.nanoseconds(); + downloadTime += Bun.nanoseconds() - last; last = now; // don't trim here lineCb(line); @@ -185,7 +184,7 @@ export async function processFilterRules( } else { let filterRules; - const downloadStart = performance.now(); + const downloadStart = Bun.nanoseconds(); try { const controller = new AbortController(); @@ -205,15 +204,15 @@ export async function processFilterRules( console.log(`Download Rule for [${filterRulesUrl.toString()}] failed`); throw e; } - downloadTime = performance.now() - downloadStart; + downloadTime = Bun.nanoseconds() - downloadStart; for (let i = 0, len = filterRules.length; i < len; i++) { lineCb(filterRules[i]); } } - console.log(` ┬ processFilterRules (${filterRulesUrl.toString()}): ${(performance.now() - runStart).toFixed(3)}ms`); - console.log(` └── download time: ${downloadTime.toFixed(3)}ms`); + console.log(` ┬ processFilterRules (${filterRulesUrl.toString()}): ${((Bun.nanoseconds() - runStart) / 1e6).toFixed(3)}ms`); + console.log(` └── download time: ${(downloadTime / 1e6).toFixed(3)}ms`); return { white: whitelistDomainSets, diff --git a/Build/lib/text-decoder-stream.ts b/Build/lib/text-decoder-stream.ts index 4dc51407..04502696 100644 --- a/Build/lib/text-decoder-stream.ts +++ b/Build/lib/text-decoder-stream.ts @@ -28,9 +28,7 @@ export class PolyfillTextDecoderStream extends TransformStream) { const decoded = decoder.decode(chunk); - if (decoded.length > 0) { - controller.enqueue(decoded); - } + controller.enqueue(decoded); }, flush(controller: TransformStreamDefaultController) { // If {fatal: false} is in options (the default), then the final call to diff --git a/Build/lib/trace-runner.ts b/Build/lib/trace-runner.ts index b2bf732f..860c73bc 100644 --- a/Build/lib/trace-runner.ts +++ b/Build/lib/trace-runner.ts @@ -1,19 +1,19 @@ import path from 'path'; const traceSync = (prefix: string, fn: () => T): T => { - const start = performance.now(); + const start = Bun.nanoseconds(); const result = fn(); - const end = performance.now(); - console.log(`${prefix}: ${(end - start).toFixed(3)}ms`); + const end = Bun.nanoseconds(); + console.log(`${prefix}: ${((end - start) / 1e6).toFixed(3)}ms`); return result; }; export { traceSync }; const traceAsync = async (prefix: string, fn: () => Promise): Promise => { - const start = performance.now(); + const start = Bun.nanoseconds(); const result = await fn(); - const end = performance.now(); - console.log(`${prefix}: ${(end - start).toFixed(3)}ms`); + const end = Bun.nanoseconds(); + console.log(`${prefix}: ${((end - start) / 1e6).toFixed(3)}ms`); return result; }; export { traceAsync }; @@ -28,10 +28,10 @@ const task = (importMetaPath: string, fn: () => Promise, customname: strin const taskName = customname ?? path.basename(importMetaPath, path.extname(importMetaPath)); return async () => { console.log(`🏃 [${taskName}] Start executing`); - const start = performance.now(); + const start = Bun.nanoseconds(); await fn(); - const end = performance.now(); - console.log(`✅ [${taskName}] Executed successfully: ${(end - start).toFixed(3)}ms`); + const end = Bun.nanoseconds(); + console.log(`✅ [${taskName}] Executed successfully: ${((end - start) / 1e6).toFixed(3)}ms`); return { start, end, taskName } as TaskResult; };