| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Thoughts on semver-ness? |
Sorry, something went wrong.
|
I'm inclined to say semver-patch. The change in behavior only affects applications that don't start up in the first place. |
Sorry, something went wrong.
There was a problem hiding this comment.
Does V8 make this and json.length === 0 equivalent instruction-wise?
Sorry, something went wrong.
There was a problem hiding this comment.
s.length === 0 is probably a bit slower. The empty string is a singleton so s === '' is basically a pointer comparison, whereas s.length needs to validate s first (although I expect it will be a fast path protected by a guard once optimized.)
Sorry, something went wrong.
|
On the example project with ~250 dependencies and only a handful without a main, how did the performance copmare? Just wondering how much the slow-down might be for an application where every package.json file does have a main and how negligible this is. |
Sorry, something went wrong.
|
Just to give a number, of the 596 package.jsons in Node’s tools/ and deps/, 364 contain the string "main", so it’s reasonable to assume that about 40 % of package.jsons in the wild can be skipped this way. |
Sorry, something went wrong.
It's the same, no statistically significant speed-up or slow-down. The string search is practically free compared to deserializing the JSON object. One potential improvement is to implement our own special-purpose JSON parser that scans for just the "main" property and ignores everything else - that would help with loading e.g. async, which has a > 50 kB package.json. That's a lot more work though and I'm not even sure it's a good idea per se. |
Sorry, something went wrong.
|
That may well be interesting to work on in future for additional performance gain. |
Sorry, something went wrong.
There was a problem hiding this comment.
Nice
Sorry, something went wrong.
|
Should this PR (except the first commit) be semver-major because of the change in module loading behavior (invalid/malformatted modules may no longer be detected)? |
Sorry, something went wrong.
|
@mscdex My opinion in case you missed it: #15767 (comment) |
Sorry, something went wrong.
It would be far more ideal to releasers if this was separate from commits that aren't that category.
If that exception bubbled up to user land I do think this (the sum of the 3 commits) is semver-major? |
Sorry, something went wrong.
If the package.json does not contain the string '"main"', skip parsing it to JSON. Note that this changes the behavior of the module loader in the presence of package.json files that don't contain legal JSON. Such files used to throw an exception but now they are simply ignored unless they contain a "main" property. To me, that seems like a good trade-off: I observe a 25% reduction in start-up time on a medium-sized application[0]. [0] https://github.com/strongloop/sls-sample-app
Move the logic from the previous commit to C++ land in order to avoid creating a new string when we know we won't parse it anyway.
|
Rebase + new CI: https://ci.nodejs.org/job/node-test-pull-request/11421/ |
Sorry, something went wrong.
If the package.json does not contain the string '"main"', skip parsing it to JSON. Note that this changes the behavior of the module loader in the presence of package.json files that don't contain legal JSON. Such files used to throw an exception but now they are simply ignored unless they contain a "main" property. To me, that seems like a good trade-off: I observe a 25% reduction in start-up time on a medium-sized application[0]. [0] https://github.com/strongloop/sls-sample-app PR-URL: nodejs#15767 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Move the logic from the previous commit to C++ land in order to avoid creating a new string when we know we won't parse it anyway. PR-URL: nodejs#15767 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
1132ea7...0fdd88a and tagged semver-major because I'm conservative like that. |
Sorry, something went wrong.
|
"\u006dain"? |
Sorry, something went wrong.
|
I think this should be revisited. InternalModuleReadFile was more generically useful before and could have been applied to loading more than just json. However, now with the introduction of this bit it essentially locks it into json only. If that's the case, I think the name InternalModuleReadFile, and the pseudo exposed process.binding("fs").internalModuleReadFile, should either be renamed or a new internal for json-only should be created (maybe that wraps InternalModuleReadFile). |
Sorry, something went wrong.
|
Does this fail if "main" is written with \u escapes? |
Sorry, something went wrong.
|
@charmander I guess it would. Can you point to a module that does that? |
Sorry, something went wrong.
Was the perf win, when applicable, primarily from the first commit (the one that didn't touch the c++ helper)? If so I think that could be enough, without having to go deeper into the internals #17084. |
Sorry, something went wrong.
|
@jdalton The second commit avoids ~300 kB of strings being created needlessly when you invoke npm. That's pretty substantial. |
Sorry, something went wrong.
What's that mean for execution time? (e.g. does it move from 25% to 30% improvement?) What I'm getting at is, that while it is nice, it's not a guaranteed perf win since it's super scenario specific (npm init creates package.json files with a "main" field) and also diminishes the usefulness from the helper (moved from generic read file fast path to only json). So it's a step too far in the name of a might-be optimization. |
Sorry, something went wrong.
|
It cuts down the number and total size of package.json strings by about 35%. To put that in perspective: even a 1% or 2% improvement would have been well worth it, every bit helps. If you don't think it's a worthwhile optimization, the onus is on you to prove it with numbers (but you'd be wasting your time because it is.) |
Sorry, something went wrong.
In the past, improvements like using InternalReadFile for more than just json, which I'm sure would fall into that category or better, were held off on because of potential breakage.
Wouldn't the responsibility be to prove the perf wins before introducing something that requires a semver major? I'm all for optimizations, but I'd like to have a more clear picture on what we're giving up usability and potential user code breakage (semver major) for. I don't think asking for the percentage wins of the second commit is unreasonable. So again, what's that mean for execution time? (e.g. does it move from 25% to 30% improvement?) |
Sorry, something went wrong.
|
The semver-major tag is just me being ultra-conservative (and also about giving people an incentive to upgrade when v10 comes out.) |
Sorry, something went wrong.
|
@bnoordhuis |
Sorry, something went wrong.
|
@bnoordhuis I can’t, but is it maybe worth also checking for \u006 to avoid making that exception? |
Sorry, something went wrong.
|
@jdalton See #4679, my original PR did that but it caused regressions on Windows and I never quite figured out why. @charmander I suppose so, I'll think about it. I don't mind doing that if it's necessary but neither do I like adding complexity and overhead for what is most likely a non-issue. |
Sorry, something went wrong.
|
@bnoordhuis might be worth trying again (with today's code base). It looks like there was other Jenkins weirdness back then too. |
Sorry, something went wrong.
|
@charmander I think it's mostly a non-issue as npm serializes and reserializes package.json during installation, which replaces \u006d with m. I don't know if Yarn does that, however. |
Sorry, something went wrong.
|
It’s a small amount of code complexity and overhead in exchange for replacing “works for almost all valid JSON representations” and “mostly a non-issue” with “works for all JSON representations” and “is a non-issue”. Is the certainty worth having? |
Sorry, something went wrong.
|
Not if it's dead code. Then it's just a place for bugs to hide. (I don't subscribe to Postel's maxim in case you wondered.) |
Sorry, something went wrong.
That doesn’t really apply here – JSON is JSON. I’ll open a PR. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The first commit is a bug fix and should be back-ported to the release branches but I'm including it here because the other commits build on top of it.
From the second commit log:
That 25% is going to depend on how many package.json files have a "main" property. With another project, only a handful out of ~250 did not have one.
CI: https://ci.nodejs.org/job/node-test-pull-request/10401/