Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use primordials #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

chore: use primordials #216

wants to merge 1 commit into from

Conversation

MoLow
Copy link

@MoLow MoLow commented Jul 4, 2023

this is just a POC to start the process of node exposing fs.glob.
if this PR will land, I will complete the process on all the rest of the code.
also, it seems like node-primordials needs some type fixes / additions

depends on isaacs/node-primordials#8 and isaacs/node-primordials#9

@MoLow
Copy link
Author

MoLow commented Jul 4, 2023

CC @isaacs

src/primordials.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,4 @@
export const primordials: any = // TODO export as typeof import('node-primordials'), types are wrong
// @ts-expect-error
typeof primordials !== 'undefined' ? primordials /* c8 ignore next */ :
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think c8 ignore next is a thing, is that new? I thought it only supported /* c8 ignore start */ and /* c8 ignore stop */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's somewhat new-ish, I think. (Like, added in the last 5 years or so probably lol.) Nice!

@isaacs
Copy link
Owner

isaacs commented Jul 5, 2023

Test failures are spurious, should be fixed by rebasing onto main to update tap.

@MoLow MoLow force-pushed the start-primodials branch 3 times, most recently from 184993c to aba228e Compare July 6, 2023 16:14
@MoLow MoLow requested a review from isaacs July 6, 2023 16:14
@MoLow
Copy link
Author

MoLow commented Jul 11, 2023

@isaacs PTAL

src/ast.ts Outdated Show resolved Hide resolved
'$',
'\\',
'!',
])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does SafeSet only take arrays, not arbitrary iterables?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the implementation here https://github.com/isaacs/node-primordials/pull/9/files# I guess it would work with any iterable, but didn't try

@isaacs
Copy link
Owner

isaacs commented Jul 11, 2023

Looks mostly fine. I'd like to get the PRs on node-primordials landed before landing this, so that it can be a simple dep update. Then the real question will be what the perf impact is, if any. If it's awful, we'll have to figure out some way to either mitigate it, or have the primordials version live side by side somehow with the normal code.

@MoLow
Copy link
Author

MoLow commented Jul 18, 2023

ping @isaacs can you take a look?

@MoLow
Copy link
Author

MoLow commented Aug 3, 2023

@isaacs as we discussed - I'v ran benchmarks on the glob repo: isaacs/node-glob@main...MoLow:node-glob:primordials
the impact seems negligible to me:


--- pattern: '**' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.647s  222999
node glob10 glob syncStream  	0m1.506s  222999
node current globSync mjs    	0m1.649s  222999
node current glob syncStream  	0m1.524s  222999
~~ async ~~
node glob10 glob async mjs   	0m0.574s  222999
node glob10 glob stream      	0m0.527s  222999
node current glob async mjs   	0m0.590s  222999
node current glob stream      	0m0.535s  222999

--- pattern: '**/..' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.292s  2268
node glob10 glob syncStream  	0m1.312s  2268
node current globSync mjs    	0m1.428s  2268
node current glob syncStream  	0m1.324s  2268
~~ async ~~
node glob10 glob async mjs   	0m0.550s  2268
node glob10 glob stream      	0m0.513s  2268
node current glob async mjs   	0m0.549s  2268
node current glob stream      	0m0.542s  2268

--- pattern: './**/0/**/0/**/0/**/0/**/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.311s  10
node glob10 glob syncStream  	0m1.274s  10
node current globSync mjs    	0m1.282s  10
node current glob syncStream  	0m1.395s  10
~~ async ~~
node glob10 glob async mjs   	0m0.538s  10
node glob10 glob stream      	0m0.517s  10
node current glob async mjs   	0m0.529s  10
node current glob stream      	0m0.520s  10

--- pattern: './**/[01]/**/[12]/**/[23]/**/[45]/**/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.293s  160
node glob10 glob syncStream  	0m1.293s  160
node current globSync mjs    	0m1.325s  160
node current glob syncStream  	0m1.296s  160
~~ async ~~
node glob10 glob async mjs   	0m0.516s  160
node glob10 glob stream      	0m0.522s  160
node current glob async mjs   	0m0.528s  160
node current glob stream      	0m0.588s  160

--- pattern: './**/0/**/0/**/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.338s  5230
node glob10 glob syncStream  	0m1.294s  5230
node current globSync mjs    	0m1.381s  5230
node current glob syncStream  	0m1.324s  5230
~~ async ~~
node glob10 glob async mjs   	0m0.513s  5230
node glob10 glob stream      	0m0.521s  5230
node current glob async mjs   	0m0.519s  5230
node current glob stream      	0m0.527s  5230

--- pattern: '**/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.414s  200003
node glob10 glob syncStream  	0m1.406s  200003
node current globSync mjs    	0m1.497s  200003
node current glob syncStream  	0m1.452s  200003
~~ async ~~
node glob10 glob async mjs   	0m0.559s  200003
node glob10 glob stream      	0m0.542s  200003
node current glob async mjs   	0m0.592s  200003
node current glob stream      	0m0.578s  200003

--- pattern: '{**/*.txt,**/?/**/*.txt,**/?/**/?/**/*.txt,**/?/**/?/**/?/**/*.txt,**/?/**/?/**/?/**/?/**/*.txt}' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.532s  200003
node glob10 glob syncStream  	0m1.428s  200003
node current globSync mjs    	0m1.560s  200003
node current glob syncStream  	0m1.462s  200003
~~ async ~~
node glob10 glob async mjs   	0m0.576s  200003
node glob10 glob stream      	0m0.611s  200003
node current glob async mjs   	0m0.620s  200003
node current glob stream      	0m0.595s  200003

--- pattern: '**/5555/0000/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.336s  1000
node glob10 glob syncStream  	0m1.285s  1000
node current globSync mjs    	0m1.293s  1000
node current glob syncStream  	0m1.300s  1000
~~ async ~~
node glob10 glob async mjs   	0m0.517s  1000
node glob10 glob stream      	0m0.566s  1000
node current glob async mjs   	0m0.545s  1000
node current glob stream      	0m0.548s  1000

--- pattern: './**/0/**/../[01]/**/0/../**/0/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.280s  4880
node glob10 glob syncStream  	0m1.302s  4880
node current globSync mjs    	0m1.330s  4880
node current glob syncStream  	0m1.318s  4880
~~ async ~~
node glob10 glob async mjs   	0m0.545s  4880
node glob10 glob stream      	0m0.534s  4880
node current glob async mjs   	0m0.537s  4880
node current glob stream      	0m0.526s  4880

--- pattern: '**/????/????/????/????/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.412s  100000
node glob10 glob syncStream  	0m1.330s  100000
node current globSync mjs    	0m1.375s  100000
node current glob syncStream  	0m1.346s  100000
~~ async ~~
node glob10 glob async mjs   	0m0.551s  100000
node glob10 glob stream      	0m0.541s  100000
node current glob async mjs   	0m0.522s  100000
node current glob stream      	0m0.545s  100000

--- pattern: './{**/?{/**/?{/**/?{/**/?,,,,},,,,},,,,},,,}/**/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.525s  200003
node glob10 glob syncStream  	0m1.470s  200003
node current globSync mjs    	0m1.542s  200003
node current glob syncStream  	0m1.436s  200003
~~ async ~~
node glob10 glob async mjs   	0m0.578s  200003
node glob10 glob stream      	0m0.544s  200003
node current glob async mjs   	0m0.631s  200003
node current glob stream      	0m0.572s  200003

--- pattern: '**/!(0|9).txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.405s  180003
node glob10 glob syncStream  	0m1.396s  180003
node current globSync mjs    	0m1.472s  180003
node current glob syncStream  	0m1.398s  180003
~~ async ~~
node glob10 glob async mjs   	0m0.530s  180003
node glob10 glob stream      	0m0.535s  180003
node current glob async mjs   	0m0.580s  180003
node current glob stream      	0m0.538s  180003

--- pattern: './{*/**/../{*/**/../{*/**/../{*/**/../{*/**,,,,},,,,},,,,},,,,},,,,}/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.560s  200003
node glob10 glob syncStream  	0m1.541s  200003
node current globSync mjs    	0m1.627s  200003
node current glob syncStream  	0m1.553s  200003
~~ async ~~
node glob10 glob async mjs   	0m0.739s  200003
node glob10 glob stream      	0m0.642s  200003
node current glob async mjs   	0m0.751s  200003
node current glob stream      	0m0.686s  200003

--- pattern: './*/**/../*/**/../*/**/../*/**/../*/**/../*/**/../*/**/../*/**/*.txt' ---
~~ sync ~~
node glob10 globSync mjs    	0m1.532s  200003
node glob10 glob syncStream  	0m1.493s  200003
node current globSync mjs    	0m1.574s  200003
node current glob syncStream  	0m1.483s  200003
~~ async ~~
node glob10 glob a