-
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
Extract out fs validation functions #17682
Conversation
lib/fs.js
Outdated
if (!isUint8Array(buffer)) | ||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'buffer', | ||
['Buffer', 'Uint8Array']); | ||
} |
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.
If we're going to separate these out, would you mind using Error.captureStackTrace()
to filter out the frame for the validation function.
e.g.
const err = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'buffer',
['Buffer', 'Uint8Array']);
Error.captureStackTrace(err, validateBuffer);
throw err;
I like this, but can we wait until #17667 lands then update to include those also? |
Code LGTM but maybe benchmark it just to make sure nothing weirdly regresses. |
One thing I don't like is the removal of the last frame from the stack trace but I guess there is no other way if we want to keep the stack trace the same as before. |
2b1400e
to
e8bc54b
Compare
PTAL -- updated after @jasnell's PR landed |
(no rush at all, but just waiting for a @jasnell approval before landing) |
still lgtm but I'd like to see a benchmark run. |
@jasnell running benchmark CI at https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/81/ (first time running that job -- let me know if I configured it wrong :) ) |
Benchmark results:
There are a few performance hits in the stream throughput benchmarks that seem significant, although this PR does not seem to touch that part of code. I've started |
@jasnell @joyeecheung It looks like the second round of benchmarks are much better than the first... is a third run needed? Is this safe to land? |
New benchmark results do not show any significant impact, I think it's safe to land.
|
Landed in 6e3818f...8aec363, thanks! |
PR-URL: #17682 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
PR-URL: #17682 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
PR-URL: #17682 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
PR-URL: #17682 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
PR-URL: #17682 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
PR-URL: #17682 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Thank you for landing @joyeecheung!! |
This isn't landing cleanly on v9.x. If it needs to be backported, can you please open a backport PR? Thanks! |
This touches a lot of code in fs and could make future backports difficult. With that being said it is a lot of churn. Should this be backported to |
Many different validations are repeated within
fs.js
, so I extracted them out to separate functions to try and DRY up the code and avoid duplicating them.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
fs