First commit

This commit is contained in:
2026-01-12 13:12:46 +01:00
parent b2d9501f6d
commit a1fbd8acf5
4413 changed files with 1245183 additions and 0 deletions

35
node_modules/find-my-way/benchmark/bench-thread.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
'use strict'
const { workerData: benchmark, parentPort } = require('worker_threads')
const Benchmark = require('benchmark')
// The default number of samples for Benchmark seems to be low enough that it
// can generate results with significant variance (~2%) for this benchmark
// suite. This makes it sometimes a bit confusing to actually evaluate impact of
// changes on performance. Setting the minimum of samples to 500 results in
// significantly lower variance on my local setup for this tests suite, and
// gives me higher confidence in benchmark results.
Benchmark.options.minSamples = 500
const suite = Benchmark.Suite()
const FindMyWay = require('..')
const findMyWay = new FindMyWay()
for (const { method, url, opts } of benchmark.setupURLs) {
if (opts !== undefined) {
findMyWay.on(method, url, opts, () => true)
} else {
findMyWay.on(method, url, () => true)
}
}
suite
.add(benchmark.name, () => {
findMyWay.lookup(...benchmark.arguments)
})
.on('cycle', (event) => {
parentPort.postMessage(String(event.target))
})
.on('complete', () => {})
.run()

156
node_modules/find-my-way/benchmark/bench.js generated vendored Normal file
View File

@@ -0,0 +1,156 @@
'use strict'
const path = require('path')
const { Worker } = require('worker_threads')
const BENCH_THREAD_PATH = path.join(__dirname, 'bench-thread.js')
const benchmarks = [
{
name: 'lookup root "/" route',
setupURLs: [{ method: 'GET', url: '/' }],
arguments: [{ method: 'GET', url: '/' }]
},
{
name: 'lookup short static route',
setupURLs: [{ method: 'GET', url: '/static' }],
arguments: [{ method: 'GET', url: '/static' }]
},
{
name: 'lookup long static route',
setupURLs: [{ method: 'GET', url: '/static/static/static/static/static' }],
arguments: [{ method: 'GET', url: '/static/static/static/static/static' }]
},
{
name: 'lookup long static route (common prefix)',
setupURLs: [
{ method: 'GET', url: '/static' },
{ method: 'GET', url: '/static/static' },
{ method: 'GET', url: '/static/static/static' },
{ method: 'GET', url: '/static/static/static/static' },
{ method: 'GET', url: '/static/static/static/static/static' }
],
arguments: [{ method: 'GET', url: '/static/static/static/static/static' }]
},
{
name: 'lookup short parametric route',
setupURLs: [{ method: 'GET', url: '/:param' }],
arguments: [{ method: 'GET', url: '/param1' }]
},
{
name: 'lookup long parametric route',
setupURLs: [{ method: 'GET', url: '/:param' }],
arguments: [{ method: 'GET', url: '/longParamParamParamParamParamParam' }]
},
{
name: 'lookup short parametric route (encoded unoptimized)',
setupURLs: [{ method: 'GET', url: '/:param' }],
arguments: [{ method: 'GET', url: '/param%2B' }]
},
{
name: 'lookup short parametric route (encoded optimized)',
setupURLs: [{ method: 'GET', url: '/:param' }],
arguments: [{ method: 'GET', url: '/param%20' }]
},
{
name: 'lookup parametric route with two short params',
setupURLs: [{ method: 'GET', url: '/:param1/:param2' }],
arguments: [{ method: 'GET', url: '/param1/param2' }]
},
{
name: 'lookup multi-parametric route with two short params',
setupURLs: [{ method: 'GET', url: '/:param1-:param2' }],
arguments: [{ method: 'GET', url: '/param1-param2' }]
},
{
name: 'lookup multi-parametric route with two short regex params',
setupURLs: [{ method: 'GET', url: '/:param1([a-z]*)1:param2([a-z]*)2' }],
arguments: [{ method: 'GET', url: '/param1param2' }]
},
{
name: 'lookup long static + parametric route',
setupURLs: [{ method: 'GET', url: '/static/:param1/static/:param2/static' }],
arguments: [{ method: 'GET', url: '/static/param1/static/param2/static' }]
},
{
name: 'lookup short wildcard route',
setupURLs: [{ method: 'GET', url: '/*' }],
arguments: [{ method: 'GET', url: '/static' }]
},
{
name: 'lookup long wildcard route',
setupURLs: [{ method: 'GET', url: '/*' }],
arguments: [{ method: 'GET', url: '/static/static/static/static/static' }]
},
{
name: 'lookup root route on constrained router',
setupURLs: [
{ method: 'GET', url: '/' },
{ method: 'GET', url: '/static', opts: { constraints: { version: '1.2.0' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'example.com' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'fastify.io' } } }
],
arguments: [{ method: 'GET', url: '/', headers: { host: 'fastify.io' } }]
},
{
name: 'lookup short static unconstraint route',
setupURLs: [
{ method: 'GET', url: '/static', opts: {} },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'example.com' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'fastify.io' } } }
],
arguments: [{ method: 'GET', url: '/static', headers: {} }]
},
{
name: 'lookup short static versioned route',
setupURLs: [
{ method: 'GET', url: '/static', opts: { constraints: { version: '1.2.0' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'example.com' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'fastify.io' } } }
],
arguments: [{ method: 'GET', url: '/static', headers: { 'accept-version': '1.x', host: 'fastify.io' } }]
},
{
name: 'lookup short static constrained (version & host) route',
setupURLs: [
{ method: 'GET', url: '/static', opts: { constraints: { version: '1.2.0' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'example.com' } } },
{ method: 'GET', url: '/static', opts: { constraints: { version: '2.0.0', host: 'fastify.io' } } }
],
arguments: [{ method: 'GET', url: '/static', headers: { 'accept-version': '2.x', host: 'fastify.io' } }]
}
]
async function runBenchmark (benchmark) {
const worker = new Worker(BENCH_THREAD_PATH, { workerData: benchmark })
return new Promise((resolve, reject) => {
let result = null
worker.on('error', reject)
worker.on('message', (benchResult) => {
result = benchResult
})
worker.on('exit', (code) => {
if (code === 0) {
resolve(result)
} else {
reject(new Error(`Worker stopped with exit code ${code}`))
}
})
})
}
async function runBenchmarks () {
let maxNameLength = 0
for (const benchmark of benchmarks) {
maxNameLength = Math.max(benchmark.name.length, maxNameLength)
}
for (const benchmark of benchmarks) {
benchmark.name = benchmark.name.padEnd(maxNameLength, '.')
const resultMessage = await runBenchmark(benchmark)
console.log(resultMessage)
}
}
runBenchmarks()

114
node_modules/find-my-way/benchmark/compare-branches.js generated vendored Normal file
View File

@@ -0,0 +1,114 @@
'use strict'
const { spawn } = require('child_process')
const chalk = require('chalk')
const inquirer = require('inquirer')
const simpleGit = require('simple-git')
const git = simpleGit(process.cwd())
const COMMAND = 'npm run bench'
const DEFAULT_BRANCH = 'main'
const PERCENT_THRESHOLD = 5
async function selectBranchName (message, branches) {
const result = await inquirer.prompt([{
type: 'list',
name: 'branch',
choices: branches,
loop: false,
pageSize: 20,
message
}])
return result.branch
}
async function executeCommandOnBranch (command, branch) {
console.log(chalk.grey(`Checking out "${branch}"`))
await git.checkout(branch)
console.log(chalk.grey(`Execute "${command}"`))
const childProcess = spawn(command, { stdio: 'pipe', shell: true })
let result = ''
childProcess.stdout.on('data', (data) => {
process.stdout.write(data.toString())
result += data.toString()
})
await new Promise(resolve => childProcess.on('close', resolve))
console.log()
return parseBenchmarksStdout(result)
}
function parseBenchmarksStdout (text) {
const results = []
const lines = text.split('\n')
for (const line of lines) {
const match = /^(.+?)(\.*) x (.+) ops\/sec .*$/.exec(line)
if (match !== null) {
results.push({
name: match[1],
alignedName: match[1] + match[2],
result: parseInt(match[3].split(',').join(''))
})
}
}
return results
}
function compareResults (featureBranch, mainBranch) {
for (const { name, alignedName, result: mainBranchResult } of mainBranch) {
const featureBranchBenchmark = featureBranch.find(result => result.name === name)
if (featureBranchBenchmark) {
const featureBranchResult = featureBranchBenchmark.result
const percent = (featureBranchResult - mainBranchResult) * 100 / mainBranchResult
const roundedPercent = Math.round(percent * 100) / 100
const percentString = roundedPercent > 0 ? `+${roundedPercent}%` : `${roundedPercent}%`
const message = alignedName + percentString.padStart(7, '.')
if (roundedPercent > PERCENT_THRESHOLD) {
console.log(chalk.green(message))
} else if (roundedPercent < -PERCENT_THRESHOLD) {
console.log(chalk.red(message))
} else {
console.log(message)
}
}
}
}
(async function () {
const branches = await git.branch()
const currentBranch = branches.branches[branches.current]
let featureBranch = null
let mainBranch = null
if (process.argv[2] === '--ci') {
featureBranch = currentBranch.name
mainBranch = DEFAULT_BRANCH
} else {
featureBranch = await selectBranchName('Select the branch you want to compare (feature branch):', branches.all)
mainBranch = await selectBranchName('Select the branch you want to compare with (main branch):', branches.all)
}
try {
const featureBranchResult = await executeCommandOnBranch(COMMAND, featureBranch)
const mainBranchResult = await executeCommandOnBranch(COMMAND, mainBranch)
compareResults(featureBranchResult, mainBranchResult)
} catch (error) {
console.error('Switch to origin branch due to an error', error.message)
}
await git.checkout(currentBranch.commit)
await git.checkout(currentBranch.name)
console.log(chalk.gray(`Back to ${currentBranch.name} ${currentBranch.commit}`))
})()

55
node_modules/find-my-way/benchmark/uri-decoding.js generated vendored Normal file
View File

@@ -0,0 +1,55 @@
'use strict'
const fastDecode = require('fast-decode-uri-component')
const Benchmark = require('benchmark')
Benchmark.options.minSamples = 500
const suite = Benchmark.Suite()
const uri = [
encodeURIComponent(' /?!#@=[](),\'"'),
encodeURIComponent('algunas palabras aquí'),
encodeURIComponent('acde=bdfd'),
encodeURIComponent('много русских букв'),
encodeURIComponent('這裡有些話'),
encodeURIComponent('कुछ शब्द यहाँ'),
encodeURIComponent('✌👀🎠🎡🍺')
]
function safeFastDecode (uri) {
if (uri.indexOf('%') < 0) return uri
try {
return fastDecode(uri)
} catch (e) {
return null // or it can be null
}
}
function safeDecodeURIComponent (uri) {
if (uri.indexOf('%') < 0) return uri
try {
return decodeURIComponent(uri)
} catch (e) {
return null // or it can be null
}
}
uri.forEach(function (u, i) {
suite.add(`safeDecodeURIComponent(${i}) [${u}]`, function () {
safeDecodeURIComponent(u)
})
suite.add(`fastDecode(${i}) [${u}]`, function () {
fastDecode(u)
})
suite.add(`safeFastDecode(${i}) [${u}]`, function () {
safeFastDecode(u)
})
})
suite
.on('cycle', function (event) {
console.log(String(event.target))
})
.on('complete', function () {
})
.run()