From 4073e5b6c9b2f4c6b4a3cea1f0f1d6f0ba89e769 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 10 Sep 2023 11:16:09 +0100 Subject: [PATCH] perf: use `node:` prefix to bypass require.cache call for builtins (#644) * perf: use `node:` prefix to bypass require.cache call for builtins See https://github.com/fastify/fastify-static/pull/407 * docs: use `node:` prefix to bypass require.cache call for builtins --- README.md | 2 +- benchmark/bench-cmp-branch.js | 2 +- benchmark/bench-thread.js | 2 +- benchmark/bench.js | 4 ++-- build/build-schema-validator.js | 4 ++-- examples/server.js | 2 +- index.js | 2 +- test/standalone-mode.test.js | 4 ++-- test/webpack.test.js | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ff1f1460..1d201adc 100644 --- a/README.md +++ b/README.md @@ -692,7 +692,7 @@ The standalone mode is used to compile the code that can be directly run by `nod itself. You need to have `fast-json-stringify` installed for the standalone code to work. ```js -const fs = require('fs') +const fs = require('node:fs') const code = fastJson({ title: 'default string', type: 'object', diff --git a/benchmark/bench-cmp-branch.js b/benchmark/bench-cmp-branch.js index a896e986..96c10a6e 100644 --- a/benchmark/bench-cmp-branch.js +++ b/benchmark/bench-cmp-branch.js @@ -1,6 +1,6 @@ 'use strict' -const { spawn } = require('child_process') +const { spawn } = require('node:child_process') const cliSelect = require('cli-select') const simpleGit = require('simple-git') diff --git a/benchmark/bench-thread.js b/benchmark/bench-thread.js index 7e3ba73e..88314358 100644 --- a/benchmark/bench-thread.js +++ b/benchmark/bench-thread.js @@ -1,6 +1,6 @@ 'use strict' -const { workerData: benchmark, parentPort } = require('worker_threads') +const { workerData: benchmark, parentPort } = require('node:worker_threads') const Benchmark = require('benchmark') Benchmark.options.minSamples = 100 diff --git a/benchmark/bench.js b/benchmark/bench.js index 12726184..d0744850 100644 --- a/benchmark/bench.js +++ b/benchmark/bench.js @@ -1,7 +1,7 @@ 'use strict' -const path = require('path') -const { Worker } = require('worker_threads') +const path = require('node:path') +const { Worker } = require('node:worker_threads') const BENCH_THREAD_PATH = path.join(__dirname, 'bench-thread.js') diff --git a/build/build-schema-validator.js b/build/build-schema-validator.js index 0c188cc4..8e4f811d 100644 --- a/build/build-schema-validator.js +++ b/build/build-schema-validator.js @@ -3,8 +3,8 @@ const Ajv = require('ajv') const standaloneCode = require('ajv/dist/standalone').default const ajvFormats = require('ajv-formats') -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const ajv = new Ajv({ addUsedSchema: false, diff --git a/examples/server.js b/examples/server.js index 706653b8..82f53775 100644 --- a/examples/server.js +++ b/examples/server.js @@ -1,6 +1,6 @@ 'use strict' -const http = require('http') +const http = require('node:http') const stringify = require('fast-json-stringify')({ type: 'object', diff --git a/index.js b/index.js index e15bc0c5..c514d73b 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const merge = require('@fastify/deepmerge')() const clone = require('rfdc')({ proto: true }) -const { randomUUID } = require('crypto') +const { randomUUID } = require('node:crypto') const validate = require('./lib/schema-validator') const Serializer = require('./lib/serializer') diff --git a/test/standalone-mode.test.js b/test/standalone-mode.test.js index 1e1570f2..5f671d01 100644 --- a/test/standalone-mode.test.js +++ b/test/standalone-mode.test.js @@ -2,8 +2,8 @@ const test = require('tap').test const fjs = require('..') -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') function build (opts, schema) { return fjs(schema || { diff --git a/test/webpack.test.js b/test/webpack.test.js index 075d64c6..dc59c29a 100644 --- a/test/webpack.test.js +++ b/test/webpack.test.js @@ -2,7 +2,7 @@ const test = require('tap').test const webpack = require('webpack') -const path = require('path') +const path = require('node:path') test('the library should work with webpack', async (t) => { t.plan(1)