-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Deep equality utility takes very long for certain types of deeply nested objects #7429
Comments
Just in case, can you confirm it's not your algo getting stuck in while loop or recursion? |
As explained in #1405, if synchronous code is taking over, then timeout doesn't kick in. You can try |
Yes it should not be, I am currently using Jest and it passes fine. I encountered the hanging issue while migrating to Vitest. I did further debugging and narrowed down the issue to this line I suspect the implementation of the |
Okay, that's likely a bug of printing/diffing a cyclic object getting stuck in the loop. |
Thanks. As a workaround I've changed my code to Updated StackBlitz repro to the minimal test case: https://stackblitz.com/edit/vitejs-vite-jtzpyjuo?file=src%2Fgraph.test.ts |
I took a look and I'm not sure if we can say this is actually a bug. It appears that cyclic structure isn't necessary a cause, but Vitest's deep equality utility is too expensive for certain types of deeply nested objects. Interestingly, Node's Here is one such structure, which shows exponential cost with respect to the number of graph nodes/edges ✓ src/repro.test.ts (20 tests) 3635ms
✓ expect().toEqual (20) 27ms
✓ expect().toEqual (21) 23ms
✓ expect().toEqual (22) 35ms
✓ expect().toEqual (23) 59ms
✓ expect().toEqual (24) 91ms
✓ expect().toEqual (25) 148ms
✓ expect().toEqual (26) 244ms
✓ expect().toEqual (27) 387ms
✓ expect().toEqual (28) 664ms
✓ expect().toEqual (29) 1018ms
✓ assert.deepStrictEqual (20) 6ms
✓ assert.deepStrictEqual (21) 8ms
✓ assert.deepStrictEqual (22) 13ms
✓ assert.deepStrictEqual (23) 20ms
✓ assert.deepStrictEqual (24) 32ms
✓ assert.deepStrictEqual (25) 54ms
✓ assert.deepStrictEqual (26) 85ms
✓ assert.deepStrictEqual (27) 139ms
✓ assert.deepStrictEqual (28) 222ms The graph here is a fairly simple DAG with ![]() The above example uses Speaking of large cyclic or nested structure, there is also a separate issue with error diff generation such as #7092. Mentioning it here just in case since that's technically a different part of the logic and error diff output might be something we can "heuristically" improve. Let me remove a bug label for now. Fixing deep equality computation issue might not be possible to fix. |
@hi-ogawa Thanks for your hard work! Updated the title to reflect the issue better |
Describe the bug
Not much to say here, Vitest just doesn't complete when I have a certain test case for an algo question, it hangs indefinitely.
No async operations involved.
I don't think it's a bug with my algo because I'm migrating from Jest which is able to successfully run all the test cases.
With Vite it doesn't complete:
Reproduction
https://stackblitz.com/edit/vitejs-vite-jtzpyjuo
This is a minimal repro with 8 test cases (
tests.json
). My original code has 100 test cases (tests.all.json
).If the last test case in
tests.json
is removed (L240-L384), the tests can complete.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: