-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
deps: add simdjson to node.js #47991
Conversation
Review requested:
|
LGTM on the tooling side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include a specific path to use simdjson and provide benchmarks to hold your statement?
json parsing code inside src folder and help us provide faster solutions.
I'm confused by this as well. What is wrong with using V8's built-in JSON parse function? |
I have a feeling that this will not run on all our supported platforms (kicked off CI to verify). Ultimately, simdjson is not significantly faster than JSON.parse() if we need the full objects in JS-land (creating the objects is the bottleneck, not parsing them). |
@mcollina It seems only AIX is failing. I opened an upstream issue and working on a fix for
I don't have sufficient data to back my claim, but this might not be a valid argument, I'm not sure. There are other places on top of JSON.parse that can be beneficial for
@mscdex Nothing is wrong with the built-in JSON parse. I'm experimenting and asking for community feedback before investing a lot of time in this. Long story short: A couple of months ago, in one of @joyeecheung's pull requests, I don't remember which one at the moment but I've communicated the idea of using |
Updated |
Ultimately it depends on what's the speedup in that operation. I'd restrain from adding a dependency without a merasurable improvement. |
We read a lot of |
@nodejs/loaders In a total of 5 tests are failing at the moment. Appreciate any help. |
1138d7a
to
c62068c
Compare
1be0fe4
to
05ed646
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay (this got buried in my inbox). It looks like (the good news is) all the failures here are related.
The error occurs after several checks against various packageJSON fields. I'm only familiar with the ESM side of modules, but I would bet your removal of packageJsonCache.set(jsonPath, filtered);
is the cause (the reads against packageJSON fields within Module._resolveFilename
(wherefrom the error is thrown) are probably trying to read from packageJsonCache
, which no-longer gets set.
* @param {string} jsonPath | ||
*/ | ||
function read(jsonPath) { | ||
if (cache.has(jsonPath)) { | ||
return cache.get(jsonPath); | ||
} | ||
|
||
const { 0: string, 1: containsKeys } = internalModuleReadJSON( | ||
const { | ||
0: includes_keys, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is javascript, where camelCase is the standard
0: includes_keys, | |
0: includesKeys, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, maybe we should have an eslint rule about this in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised there isn't one @aduh95 I do you know if this has been discussed previously?
be620d3
to
d1899e9
Compare
I've reduced the failed tests to the following:
@RafaelGSS Any idea why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't know anything about the remaining tests—they pre-date me and basically haven't been touched in years.
const packageJsonCache = new SafeMap(); | ||
|
||
function readPackage(requestPath) { | ||
const jsonPath = path.resolve(requestPath, 'package.json'); | ||
|
||
const existing = packageJsonCache.get(jsonPath); | ||
if (existing !== undefined) return existing; | ||
|
||
const result = packageJsonReader.read(jsonPath); | ||
const json = result.containsKeys === false ? '{}' : result.string; | ||
if (json === undefined) { | ||
packageJsonCache.set(jsonPath, false); | ||
return false; | ||
} | ||
|
||
try { | ||
const filtered = filterOwnProperties(JSONParse(json), [ | ||
'name', | ||
'main', | ||
'exports', | ||
'imports', | ||
'type', | ||
]); | ||
packageJsonCache.set(jsonPath, filtered); | ||
return filtered; | ||
} catch (e) { | ||
e.path = jsonPath; | ||
e.message = 'Error parsing ' + jsonPath + ': ' + e.message; | ||
throw e; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oow, nice. It looks like this code was actually redundant to package_config.js
/ getPackageConfig()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! We were having 2 different caches and duplicated code for both in ESM and CJS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm actually was that a bug or a feature? 🤔
@guybedford do you know is CJS and ESM are supposed to have different package.json caches?
* Returns undefined for all failure cases. | ||
* @param {string} jsonPath | ||
*/ | ||
function read(jsonPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to include a @returns
with the type and explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the JSDOC to the following. Let me know, if it is not sufficient:
/**
* Returns undefined for all failure cases.
* @param {string} jsonPath
* @returns {{
* name?: string,
* main?: string,
* exports?: string | Record<string, unknown>,
* imports?: string | Record<string, unknown>,
* type: 'commonjs' | 'module' | 'none' | unknown,
* } | undefined}
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would move the Returns undefined for all failure cases.
after the type for @returns
(and merely say `undefined` on failure
)
Also, I think the type for exports' & imports' Record value is known (I think it's a resolved URL['href']
?), but maybe unknown
is fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this has been open for longer than seven days and has a sign off, I'm going to request changes to prevent this from accidentally landing until benchmarks are provided.
Since there is a push after that review, it will never get merged without a new approved review. |
To be honest, I don't think there should be an approval on this PR at all yet, so it's entirely possible that another premature approval could happen. |
a80c028
to
75f9437
Compare
This would remove all our json parsing code inside
src
folder and help us provide faster solutions. I'm happy to add an example implementation to this pull-request if requested.cc @lemire