Skip to content

module: ignore package.json/ directories#18261

Closed
bmeck wants to merge 4 commits into
nodejs:masterfrom
bmeck:issue-8307
Closed

module: ignore package.json/ directories#18261
bmeck wants to merge 4 commits into
nodejs:masterfrom
bmeck:issue-8307

Conversation

@bmeck

@bmeck bmeck commented Jan 19, 2018

Copy link
Copy Markdown
Member

Fixes: #8307

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

module

@nodejs-github-bot nodejs-github-bot added the module Issues and PRs related to the module subsystem. label Jan 19, 2018
@jdalton

jdalton commented Jan 19, 2018

Copy link
Copy Markdown
Member

Could this be handled at the C++ level of the InternalModuleReadFile/InternalReadModuleJSON methods instead? That way the guard isn't needed to be added to each potential use of the internal method.

@bmeck

bmeck commented Jan 19, 2018

Copy link
Copy Markdown
Member Author

@jdalton could, but then it won't be in the stat cache.

@jdalton

jdalton commented Jan 19, 2018

Copy link
Copy Markdown
Member

Is there a way to share a cache between C++ helpers and external...
kinda like the statValues typed array?

@bmeck

bmeck commented Jan 19, 2018

Copy link
Copy Markdown
Member Author

@jdalton the statValues approach has a known size, the stat cache is a growable Map. I don't think the same approach can be used.

@jdalton

jdalton commented Jan 19, 2018

Copy link
Copy Markdown
Member

Ah, okay.

@guybedford

Copy link
Copy Markdown
Contributor

If internalModuleReadJSON returned an empty string in this case, surely that would be cached as an empty main resulting in the same behaviour, whilst avoiding round-tripping latency?


try {
require(fixtures.path('module-package-json-directory'));
process.exit(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be better to assert.fail here instead? I'm thinking from the point of view of how it might look in the CI if the test failed here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we just use assert.throws()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it would just be caught by the catch below.

@TimothyGu TimothyGu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with @richardlau's comment fixed.

@bnoordhuis bnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This shouldn't land as-is. A lot of time and effort has been spent on making this particular code path fast.

Comment thread lib/module.js Outdated
return entry;

const jsonPath = path.resolve(requestPath, 'package.json');
const rc = stat(jsonPath);

@bnoordhuis bnoordhuis Jan 20, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't introduce extra system calls that are practically never necessary. Handle it inside InternalModuleReadJSON(), it's the CHECK_GE(numchars, 0) in that function.

edit: since it's easier to just write it than try and explain it: #18270

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

resolved

@bmeck

bmeck commented Jan 20, 2018

Copy link
Copy Markdown
Member Author

@bnoordhuis your requests have been upstreamed to this PR

@bmeck

bmeck commented Jan 20, 2018

Copy link
Copy Markdown
Member Author

@guybedford changed to use ""

@jdalton moved to InternalModuleReadJSON

targos
targos previously approved these changes Jan 20, 2018
@bmeck

bmeck commented Jan 20, 2018

Copy link
Copy Markdown
Member Author

there was a bug in how packageMainCache was checking for entries if it InternalModuleReadJSON returned an empty string since it only checked falsey values. This has been fixed but I'd like a rereview due to that change.

@bnoordhuis

Copy link
Copy Markdown
Member

@bmeck Taking my code and merging that as your own without attribution or even so much as a thank you... that's not a nice thing to do.

@bmeck

bmeck commented Jan 20, 2018

Copy link
Copy Markdown
Member Author

@bnoordhuis I'd agree but have similar thoughts on repeated interactions with you. I'll add your attribution, you didn't seem to have any attribution or care about my efforts on your PR either though.

bnoordhuis and others added 3 commits January 20, 2018 09:50
@bnoordhuis

Copy link
Copy Markdown
Member

you didn't seem to have any attribution [..] on your PR

That's because there's nothing to attribute, I didn't take code or ideas from this PR.

@bmeck

bmeck commented Jan 20, 2018

Copy link
Copy Markdown
Member Author

@bnoordhuis your statements reinforce my feelings being similar to yours at being upset at the other person.

@bmeck

bmeck commented Jan 27, 2018

Copy link
Copy Markdown
Member Author

moving conversation to @bnoordhuis 's PR after having problems with differences in internal consistency choices. it ended up expanding the decision making process and can be discussed there.

@bmeck bmeck closed this Jan 27, 2018
@jdalton

jdalton commented Jan 27, 2018

Copy link
Copy Markdown
Member

Moved to #18270.

@bmeck bmeck reopened this Jan 29, 2018
@bmeck

bmeck commented Jan 29, 2018

Copy link
Copy Markdown
Member Author

Reopened for comparative review from @nodejs/tsc .

@jasnell

jasnell commented Jan 29, 2018

Copy link
Copy Markdown
Member

Actual benchmark run so we're not just guessing about potential perf impact: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/109/console

@jasnell

jasnell commented Jan 29, 2018

Copy link
Copy Markdown
Member

At least for the module-loader microbenchmarks, there is no appreciable impact ...

                                                                        confidence improvement accuracy (*)    (**)   (***)
 module/module-loader.js useCache="false" fullPath="false" thousands=50                -1.83 %       ±5.23%  ±6.96%  ±9.05%
 module/module-loader.js useCache="false" fullPath="true" thousands=50                  1.49 %       ±4.89%  ±6.51%  ±8.48%
 module/module-loader.js useCache="true" fullPath="false" thousands=50                  0.31 %      ±10.37% ±13.80% ±17.98%
 module/module-loader.js useCache="true" fullPath="true" thousands=50                   1.14 %      ±10.69% ±14.23% ±18.54%

Not sure how much (if at all, that benchmark exercises this code, however)

@bnoordhuis

Copy link
Copy Markdown
Member

FWIW, I benchmark using one of the loopback sample apps (loads ~5,000 files and did something like 250K stat calls at first, IIRC) but any biggish real-world application should do. Warming up the disk cache with a few trial runs is a good idea.

@jasnell

jasnell commented Jan 29, 2018

Copy link
Copy Markdown
Member

Ok, do you have any numbers from the loopback sample that show the changes in this PR being a problem?

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@targos targos dismissed their stale review February 6, 2018 08:13

outdated

@targos

targos commented Feb 6, 2018

Copy link
Copy Markdown
Member

I am not against this PR but I would prefer to have the cache changes in a separate one

@Trott

Trott commented Feb 8, 2018

Copy link
Copy Markdown
Member

Closed in favor of #18270. (If that's not the right thing to do, by all means, re-open!).

@Trott Trott closed this Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Issues and PRs related to the module subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

module: node aborts when package.json is a directory