-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
super slowdown with power assert / jsx / stateless component #616
Comments
I looked around a lot in the code, but eventually got lost, so any help would be awesome. Even if it's just a pointer at how to better test. |
To be clear, the difference is: import test from 'ava';
import { render } from 'react-dom'
import React from 'react';
function CustomComponent({ value }) { return <input value={value} /> }
+ test('does something slow', t => {
- test('does something fast', t => {
const div = document.createElement('div')
render(<CustomComponent value="3" />, div)
const originInput = div.getElementsByTagName('input')[0]
- const val = originInput.value
- t.same(val, 33)
+ t.same(originInput.value, 33)
}) |
I'm thinking that this may have more to do with the DOM node rather than JSX. If I'm not mistaken, @xjamundx is using jsdom. |
Yeah JSDOM is probably getting us. Power assert is probably looping over the parent nodes or something and it infinite loops. A test timeout might have helped |
// @twada |
Does this happen only when tests fail, or even for passing tests? If it is happening only for failing tests, then |
It is only happening for The furthest I could figure out how to dive into the code was this which was very slow in these cases: |
This is related to the fact that we serialize objects in the child thread and pass them to the parent thread for rendering by power-assert formatters. We did it this way because power-assert formatters introduce a non-trivial Perhaps a better way would be to revert back to rendering error output in child threads, but lazy-require the formatters. Things would slow down a bit if you have errors in every test file, but should be just as fast if not faster if you have no errors or only have errors in one or two test files.
Update: I'm not sure the crossed out sections above are the problem. |
I just tried this on global.document = require('jsdom').jsdom('<body></body>');
global.window = document.defaultView;
global.navigator = window.navigator;
import test from 'ava';
import { render } from 'react-dom'
import React from 'react';
function CustomComponent({ value }) { return <input value={value} /> }
for (var i = 0; i < 100; i++) {
(function (i) {
test('does something slow ' + i, t => {
const div = document.createElement('div')
render(<CustomComponent value="3" />, div)
const originInput = div.getElementsByTagName('input')[0]
t.same(originInput.value, 33) // assert on a reference to the value
})
})(i)
} With the following ava config in package.json: "ava": {
"babel": {
"presets": [
"react",
"stage-2",
"es2015"
]
}
} I get a runtime of |
@xjamundx - Can you try against master?
You will also need to set up your AVA config "ava": {
"babel": "inherit"
} |
I'll try to come up with a better test case. I had repro'd this issue on master as of 2 days ago, but let me check. THANKS for looking very seriously into this. |
I just tried on |
I added a |
Things start to compound when it's multiple files. As well. I did this in 10 files and the numbers are like this:
That was adding those lines in https://github.com/sindresorhus/ava/blob/45f96bd516a91bb0f9cec71b4e2664b712177e12/lib/runner.js#L111
full test code (yes it's sloppy):
full test command:
|
The number of files is not going to have an impact. Each one gets it's own process. If you are using |
Also, make sure you have
Babel is way more performant with |
Right. |
I'll open a repo with just the tests I'm using tonight. |
Narrowed it down a bit more. This super slowdown only appears when I pull in a massive dependency. Again, it's only slow when the test is failing AND i'm using power assert directly on the DOm element value AND when i'm using a massive dependency (react-intl in this case) in one of the modules that is being tested. So it's clear to me now (Esp. with Require times when I do this (this is example is just a single file with 2 tests in it): t.same(input.value, amount + 2) HUGE Start time: (2016-03-09 07:09:52 UTC) [treshold=1%] # module time %
1 babel-types (../....es/lib/index.js) 146ms ▇ 1%
2 ./lib/api/node.js...lib/api/node.js) 264ms ▇ 2%
3 babel-core (../.....l-core/index.js) 265ms ▇ 2%
4 babel-register (....ter/lib/node.js) 307ms ▇ 2%
5 core-js/shim (../...core-js/shim.js) 225ms ▇ 2%
6 babel-polyfill (....ll/lib/index.js) 230ms ▇ 2%
7 cssstyle (../../....eDeclaration.js) 192ms ▇ 1%
8 ../level2/style (...level2/style.js) 206ms ▇ 2%
9 ./jsdom/living (....living/index.js) 334ms ▇ 3%
10 jsdom (../../../....om/lib/jsdom.js) 347ms ▇ 3%
11 /Users/jamufergus...tup-test-env.js) 899ms ▇▇▇ 7%
12 ./lib/React (../....ct/lib/React.js) 165ms ▇ 1%
13 react (../../../..../react/react.js) 165ms ▇ 1%
14 react-intl (../.....t-intl/index.js) 261ms ▇ 2%
15 ./i18n (../../../...8n/dist/i18n.js) 342ms ▇ 3%
16 react-i18n (../.....n/dist/index.js) 342ms ▇ 3%
17 ../Slow (../Slow.js) 707ms ▇▇▇ 6%
18 /Users/jamufergus...SlowFields.js) 868ms ▇▇▇ 7%
Total require(): 4115
Total time: 12.9s vs. const { value } = input
t.same(value, amount + 2) Which results in Start time: (2016-03-09 07:11:03 UTC) [treshold=1%]
# module time %
1 got (node_modules/got/index.js) 42ms ▇ 2%
2 package-json (nod...e-json/index.js) 47ms ▇ 2%
3 latest-version (n...ersion/index.js) 47ms ▇ 2%
4 update-notifier (...tifier/index.js) 102ms ▇▇ 4%
5 meow (node_modules/meow/index.js) 27ms ▇ 1%
6 bluebird (node_mo...ase/bluebird.js) 39ms ▇ 1%
7 ./lib/create (nod...r/lib/create.js) 55ms ▇ 2%
8 power-assert-form...matter/index.js) 56ms ▇ 2%
9 ./api (node_modules/ava/api.js) 88ms ▇▇ 3%
Total require(): 505
Total time: 2.7s Close to a simplied test case I can upload, but not tonight, sorry.. Thanks again for all of your help |
@xjamundx Thank you for your great information. |
It must be fixed in a downstream dependency, because after uninstalling and reinstalling I can't reproduce anymore. Even on 🎉 thanks all for trying super hard to help here |
Description
If you add a test that looks like this (add it 4 or 5x to get the full impact):
It will run fast
But if you do this it will be very slow
Changing it to use
assert
will also make it run very fast, so this is probably a power-assert issue, but I don't know that as well.In the little test case, it may add up to 1s to the full test output (timed with
DEBUG=ava
), but in my real life app it added10s
after the first test20s
after the second, etc until my tests just hung.Possibly related to power-assert-js/power-assert#34
Environment
ava@latest
and0.9.2
The text was updated successfully, but these errors were encountered: