GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||
GeezerVison is showing github.com — util: add computeTime option to inspect by BridgeAR · Pull Request #19994 · nodejs/node Conversation
|
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
s/absolut/absolute/
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
If we really want to go this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Comment addressed. @mscdex I thought about that as well but the implementation becomes more difficult in that case. Right now I can not think of a implementation with a single variable when using New CI https://ci.nodejs.org/job/node-test-pull-request/14237/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
hrtime is definitely the better choice |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
/ping @nodejs/util |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Here is a snippet to conver to hrtime to millis. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is making |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
if we're so worried about the time of this that we're adding timeouts to it, perhaps we should start looking at what takes up all this time. IMO if something needs a time limit like this it shouldn't exist how it currently is. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
IMHO the best solution is to apply an algorithm that removes circular dependencies, such as https://github.com/davidmarkclements/fast-safe-stringify/blob/master/index.js#L18-L43. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: a `INSPECTION_TIMEOUT` -> an `INSPECTION_TIMEOUT`
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: more than 100 more -> more than 100?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That has a different meaning though.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like "If it takes 100 milliseconds more"? I am not sure, but more than 100 more sounds a bit heavy.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think that is not unambiguous enough. I see your point of improving the wording though.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
About the performance bottleneck: it is not about circular references. It is
I totally understand that this is not ideal but I doubt that blocking the event loop is any better. There were multiple cases before where people complained about a blocked event loop. That was also the reason for the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I switched to process.hrtime, addressed the doc nit and increased the default timeout to 300 + 100 ms. New CI https://ci.nodejs.org/job/node-test-pull-request/14247/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Then the logical thing to do is to concoct an Strawman: start with
Why is that? Performance or compatibility? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can't we just pass the previous process.hrtime() value to process.hrtime() to get a time difference and then compare that value instead?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that requires a second property on the ctx object and I would like to prevent that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Partially yes, partially no. To improve the performance of I also already spoke with @bmeurer about the problem with
Both. The performance highly depends on what object it is. For e.g., arrays it is worse to use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
We could add something like It's not exactly trivial and I'd have to check if properties of dictionary mode objects can be counted in better than O(n) time but I'm reasonably sure that for everything else it can be done in amortized O(1). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That is exactly what I asked @bmeurer for. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Just a heads up about |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Seems like there was a bug in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
To give a better idea here, this definitely is not about circular references. The issue that triggered this is a failure in npm update after @BridgeAR changed the default depth to infinity. npm uses massive in memory objects that cause inspect to choke. At a depth of 8, one npmlog call generates a single string that is 6.6 M and over 81k lines long. These are deep objects that do not contain a lot of keys but there are many many of them. They also happen to contain the full readme.md content of every dependency in a modules graph. The current inspect impl is depth first and concats strings recursively upwards using a variety of string concats, template strings, and array joins. For this one object that results in an absolutely massive amount of memory thrashing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
No matter the two perf optimizations that I opened: I still believe that this is probably a good idea. The reason is that this way there is a guarantee that the event loop is not blocked for to long. It should probably only be a "last resort" thing, so I update the warning time to 1000 ms and the bail out to 1250 ms. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
8f01bef to
6a078ac
Compare
|
I updated the code to use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Some comments:
There is no opt-in or even an opt-out, it's an always-on feature. The best you can do is set it to a real high value. At least make it accept Infinity as an opt-out but I think it should be opt-in.
Calling process.hrtime() so frequently is going to result in performance regressions.
This PR essentially assumes that process.hrtime() is free when in fact it can take 100+ microseconds on some systems. It's going to dominate with some workloads.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just maxTime? I'm sure everyone will understand that to be wall clock time, i.e., human time.
maxClockTime inevitably raises the question "what clock?"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think you misspelled this... you're using inspectDefaultOptions.maxClockTime further down at any rate.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If you add a comma, the diff will be less noisy next time.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Cache the result of getClockTime(). process.hrtime() is not necessarily cheap.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
6a078ac to
97d92fc
Compare
|
I completely rewrote the implementation to actually now rely on a "complexity" first. It is counted together by checking the inspected properties and by normalizing these in a few places (error inspection and complex keys take quite some time). After reaching a complexity of 1e5 it will check each further 1e5 if a second has passed. If that is the case, it will immediately limit all further inspection to the bare minimum and trigger a warning. Using this complexity should a) address the concerns about the overhead measuring the time and b) also address the concerns about a non deterministic return value. In my tests where my CPU was randomly on fire from different other sources it returned in about 70% the same entry and in all other cases just up to two other results. So the range in which the value might differ is now also limited to a absolut minimum and in most cases it should just always return the same value. All of this does not apply to small objects as they would not reach the complexity of 1e5 or take more than one second to compute. The current numbers came out to be reliable in a bunch of tests that I wrote specifically to test for this but that do not seem to be useful to be added as general tests (I checked e.g., very different objects and the time it took to compute those, computation with a high heap memory usage and other things). If requested, I can also open a new PR since the implementation differs significantly from the original approach. CI https://ci.nodejs.org/job/node-test-pull-request/14914/ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This can also land as a semver-minor in case the default is first set to Infinity. That way everything would behave exactly as before. As semver-major it could then be set to 1e5. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looks like related CI failures on Windows and Linux. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I fixed the CI issues by skipping the test on 32bit systems. The maximum string size can otherwise easily be reached in one second. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is this obsolete? I can't find this option in the doc.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is this reverted? The doc still states 2.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It would be nice to get some reviews here :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
1e08b92 to
a8d6f6b
Compare
|
Rebased due to conflicts. New CI https://ci.nodejs.org/job/node-test-pull-request/15002/ @addaleax @mscdex @jasnell @mcollina @Trott @bnoordhuis @joyeecheung PTAL |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a8d6f6b to
8dba214
Compare
|
Rebased due to conflicts. CI https://ci.nodejs.org/job/node-test-pull-request/15078/ This solves a big issue with util.inspect and it would be great if it could get any more attention. Shall I close this PR and reopen it? @nodejs/tsc PTAL |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
typo: immediately trigger
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I’d prefer it if we could split this into one option that sets a complexity maximum and one that sets an overall time limit
And ideally both with value Infinity so that we can split the semver-majorness out into a separate PR
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I am fine with setting this to Infinity first and then to change the default.
However, I would really prefer to have a single option for this. We already have quite a few options and IMO setting this super fine grained does not really help. I guess we could already call this maxComplexity instead of min while keeping the functionality as is and just rewording it a bit.
We could also bind the extra time to the requested complexity as in timeout after Math.floor(opts.complexity / 100) ms.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think the rename to maxComplexity is a good idea.
I do think we should always provide some way to limit the complexity while still getting absolutely deterministic results (i.e. no timer). This PR optimizes for the common case of Node.js usage, but for some applications determinism is a paramount property and we should not disable those use cases.
I agree that we already a larger number of options here than what would be ideal, but I think making these two options would be the best approach atm.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I thought again about the necessity for determinism: if an application requires that, it would very likely require the whole object to be inspected. Therefore it would require setting the value to Infinity. The reason is that the application asked for the whole inspection, nothing else. Having a limited output due to a limitation in complexity on Node.js side would therefore always be an issue.
So I still believe we should keep the functionality as I implemented it right now. I also thought about overloading the input type to accept numbers as budget and strings with ms at the end as a time budget but I withdraw that after trying to look at it again out of the perspective of the described application.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think it’s fine to ping @nodejs/collaborators for a change like this :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you add a trailing comma? Ditto on line 309.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep this as is currently. I agree that it would be better to change this but it does not seem like others agree. So I would only want to change this if eslint/eslint#10350 gets implemented and we use that rule.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Okay, fair enough.
I've been surreptitiously sneaking in commas though. Don't tell.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Leaving out wall time tracking results in a simpler algorithm.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The point is: without this it is hard to tell how much time this will actually need on different CPUs. Using the wall time is future proof by always delivering the best result with a best effort mechanism.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What I mean is, is tracking any kind of time necessary?
What you call complexity, I would call budget. You start with a fixed budget and spend it until it's gone.
Since you have that kind of logic in place already, and since it's deterministic and clock agnostic, why also track time?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Budget is indeed a good description. I am just not sure if this would be understood by looking at a option named budget.
Relying on the budget completely without checking the wall time as well means I can measure the time it takes on my machine and estimate a arbitrary time limit that should not be exceeded in the default case (e.g. 1000-1250 ms as currently done). However, we also have Raspberry PIs and similar and their CPUs are much much slower and the same budget would get spend slower and therefore block the event loop longer. Our CPUs in general get faster over time with new inventions though, so the current default case for a fast machine would soon drop and the budget is spend faster. Meaning the maximum time the event loop would be allowed to be blocked would drop to e.g., 250ms instead of the current limit.
Using both together makes sure that it will always be around the 1000-1250ms range. That is the reason why I would like to have the combination of both, even though it is not fully deterministic after spending the complete budget.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point. Have you considered splitting it out into two separate options, one for budget/complexity and one for wall time? Or are you saying that you feel a single option is best?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I feel a single option is best for two reasons:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can we add tests that test the limits here?
I think we need a test for the complexity parameter to make sure it works
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is tested implicitly here. Without the option being set the test would crash.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@BridgeAR I realize, but for example if we break the code that parses the option then tests wouldn't catch it - so if it's not a lot of trouble I think adding a second test that sets the configuration explicitly is a good idea.
Definitely not blocking on this though.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
To limit the maximum computation time this adds a `minComplexity` option. Up to that complexity any object will be fully inspected. As soon as that limit is reached the time is going to be measured for the further inspection and the inspection is limited to the absolute minimum after one second has passed. That makes sure the event loop is not blocked for to long while still producing a good output in almost all cases. To make sure the output is almost deterministic even though a timeout is used, it will only measure the time each 1e5 complexity units. This also limits the performance overhead to the minimum.
8dba214 to
2de779a
Compare
|
Closing in favor of #22756 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
npm: last nightly / v8-canary makenpm update unusable
There was an error while loading. Please reload this page.