Skip to content

Commit

Permalink
perf(airlight-resolve): improve performance of resolver [skip ci]
Browse files Browse the repository at this point in the history
docs(examples): add benchmark example [skip ci]
  • Loading branch information
dalisoft committed Jan 4, 2024
1 parent 8e00e8f commit 3e91116
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/airlight-resolve/bench/bench-1.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable filename-rules/match, no-console */

const resolve = require('../resolve.cjs');

const ITERATEE = 1_000_000;

console.time('nodejs resolve');
for (let i = 0; i < ITERATEE; i++) {
require.resolve(`${process.cwd()}/package.json`);
}
console.timeEnd('nodejs resolve');

console.time('airlight-resolve');
for (let i = 0; i < ITERATEE; i++) {
resolve(`${process.cwd()}/package.json`);
}
console.timeEnd('airlight-resolve');
2 changes: 1 addition & 1 deletion packages/airlight-resolve/resolve.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const { ResolverFactory } = require('oxc-resolver');

const factory = new ResolverFactory({});
module.exports = function customResolve(...args) {
return factory.sync(args[0], args.join('/')).path;
return factory.sync(args[0], args.length < 2 ? args[0] : args.join('/')).path;
};
2 changes: 1 addition & 1 deletion packages/airlight-resolve/resolve.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { ResolverFactory } from 'oxc-resolver';

const factory = new ResolverFactory({});
export default function customResolve(...args) {
return factory.sync(args[0], args.join('/')).path;
return factory.sync(args[0], args.length < 2 ? args[0] : args.join('/')).path;
}

0 comments on commit 3e91116

Please sign in to comment.