From a449b5852f851c943360152c6acba7033ea48c23 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 11 Sep 2023 23:02:17 +0200 Subject: [PATCH] perf: use node: prefix to bypass caching call for builtins MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- benchmarks/internal/cluster-worker.mjs | 2 +- benchmarks/internal/thread-worker.mjs | 2 +- .../versus-external-pools/functions/function-to-bench.js | 4 ++-- examples/javascript/yourWorker.js | 2 +- .../http-server-pool/express-cluster/src/worker.ts | 4 ++-- .../http-server-pool/express-hybrid/src/express-worker.ts | 4 ++-- .../fastify-hybrid/src/fastify-poolifier.ts | 2 +- .../fastify-worker_threads/src/fastify-poolifier.ts | 2 +- examples/typescript/pool.ts | 4 ++-- tests/pools/abstract/abstract-pool.test.js | 2 +- tests/pools/abstract/worker-node.test.js | 4 ++-- tests/utils.test.js | 8 ++++---- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/benchmarks/internal/cluster-worker.mjs b/benchmarks/internal/cluster-worker.mjs index f6b3b056..69a7ad15 100644 --- a/benchmarks/internal/cluster-worker.mjs +++ b/benchmarks/internal/cluster-worker.mjs @@ -1,4 +1,4 @@ -import { isPrimary } from 'cluster' +import { isPrimary } from 'node:cluster' import { ClusterWorker } from '../../lib/index.mjs' import { executeTaskFunction } from '../benchmarks-utils.mjs' import { TaskFunctions } from '../benchmarks-types.mjs' diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index 94250a3a..7af5fa63 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -1,4 +1,4 @@ -import { isMainThread } from 'worker_threads' +import { isMainThread } from 'node:worker_threads' import { ThreadWorker } from '../../lib/index.mjs' import { executeTaskFunction } from '../benchmarks-utils.mjs' import { TaskFunctions } from '../benchmarks-types.mjs' diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index ecc39a1c..ff13bc9e 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.js @@ -6,8 +6,8 @@ * @returns {*} The result. */ const functionToBench = data => { - const crypto = require('crypto') - const fs = require('fs') + const crypto = require('node:crypto') + const fs = require('node:fs') const TaskTypes = { CPU_INTENSIVE: 'CPU_INTENSIVE', IO_INTENSIVE: 'IO_INTENSIVE' diff --git a/examples/javascript/yourWorker.js b/examples/javascript/yourWorker.js index c21f911d..cc462f7f 100644 --- a/examples/javascript/yourWorker.js +++ b/examples/javascript/yourWorker.js @@ -1,5 +1,5 @@ 'use strict' -const { isMainThread } = require('worker_threads') +const { isMainThread } = require('node:worker_threads') const { ThreadWorker } = require('poolifier') const debug = false diff --git a/examples/typescript/http-server-pool/express-cluster/src/worker.ts b/examples/typescript/http-server-pool/express-cluster/src/worker.ts index da1066c4..c5fe74ac 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/worker.ts @@ -1,5 +1,5 @@ -import type { Server } from 'http' -import type { AddressInfo } from 'net' +import type { Server } from 'node:http' +import type { AddressInfo } from 'node:net' import { ClusterWorker } from 'poolifier' import express, { type Express, type Request, type Response } from 'express' import { type WorkerData, type WorkerResponse } from './types.js' diff --git a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts index db05cdbe..c7ca23ad 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts @@ -1,5 +1,5 @@ -import type { Server } from 'http' -import type { AddressInfo } from 'net' +import type { Server } from 'node:http' +import type { AddressInfo } from 'node:net' import { ClusterWorker, DynamicThreadPool, diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts index 7426ed46..2d137580 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts @@ -1,4 +1,4 @@ -import type { TransferListItem } from 'worker_threads' +import type { TransferListItem } from 'node:worker_threads' import { DynamicThreadPool, availableParallelism } from 'poolifier' import { type FastifyPluginCallback } from 'fastify' import fp from 'fastify-plugin' diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts index 85e22c12..74c0c168 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts @@ -1,4 +1,4 @@ -import type { TransferListItem } from 'worker_threads' +import type { TransferListItem } from 'node:worker_threads' import { DynamicThreadPool, availableParallelism } from 'poolifier' import { type FastifyPluginCallback } from 'fastify' import fp from 'fastify-plugin' diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index 93774422..3d9d9e6f 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,5 +1,5 @@ -import { dirname, extname, join } from 'path' -import { fileURLToPath } from 'url' +import { dirname, extname, join } from 'node:path' +import { fileURLToPath } from 'node:url' import type { MyData, MyResponse } from './worker' import { DynamicThreadPool, diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index a206948f..bedb1c6c 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1,4 +1,4 @@ -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const { expect } = require('expect') const sinon = require('sinon') const { diff --git a/tests/pools/abstract/worker-node.test.js b/tests/pools/abstract/worker-node.test.js index 4b325f43..c57ce953 100644 --- a/tests/pools/abstract/worker-node.test.js +++ b/tests/pools/abstract/worker-node.test.js @@ -1,5 +1,5 @@ -const { MessageChannel, Worker } = require('worker_threads') -const cluster = require('cluster') +const { MessageChannel, Worker } = require('node:worker_threads') +const cluster = require('node:cluster') const { expect } = require('expect') const { WorkerNode } = require('../../../lib/pools/worker-node') const { WorkerTypes } = require('../../../lib') diff --git a/tests/utils.test.js b/tests/utils.test.js index 426985a2..5041f102 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,7 +1,7 @@ -const { randomInt } = require('crypto') -const { Worker } = require('worker_threads') -const cluster = require('cluster') -const os = require('os') +const { randomInt } = require('node:crypto') +const { Worker } = require('node:worker_threads') +const cluster = require('node:cluster') +const os = require('node:os') const { expect } = require('expect') const { CircularArray, -- 2.34.1