ts-type-explorer icon indicating copy to clipboard operation
ts-type-explorer copied to clipboard

Improve performance with lazy processing / calculation timeout

Open finnmerlett opened this issue 4 months ago • 1 comments

I suddenly started having my intellisense hang indefinitely on a cypress project, and after an extension bisect found ts-type-explorer was the issue. Thankfully I solved the problem by lowering the max recursion depth to 4. I figured the type-structure must have branched out too rapidly, but it made me think there must be a better way to handle recusion calculation overload. My suggestions are:

  1. Only explore and find the types when the user expands that part of the type explorer.

    • There is no point collecting n-levels depth of type information if the nodes are collapsed, and this approach would prevent the exponential slowdown as depth increases. It would also remove the need to set a hard cap on the depth explorable.
    • EDIT: I do see that another user asked about this issue, and that the answer was: it was already implemented on some, but tricky to implement on specific types of types
  2. Allow the user to set a calculation timeout at which point to stop further recursing.

    • This could be used instead of a hard depth stop, particularly if the approach was to calculate level n of recursion for the entire tree, before level n+1. This would fit better with a variety of codebase sizes and complexities, and also let the user know what was going wrong if their computer had ground to a halt.

Also to note - I was having my intellisense hang even when I had not focused the type-explorer tab. This feels like a mis-step, I wouldn't mind a delay when opening the tab, if it meant a more performant codebase the rest of the time. A spinner and a "stop calculation" button would be good UI additions too.

finnmerlett avatar Mar 17 '24 22:03 finnmerlett

I am having my whole VSCode hang when @tanstack/react-form is installed. After disabling all extensions one by one, I have figured out that the Typescript Explorer was causing this issue.

Example bare-minimum repo where you can observe the issue:

https://github.com/virtuallyunknown/tanstack-form-performance

https://github.com/mxsdev/ts-type-explorer/assets/24871108/00444bd4-cea7-4a01-9fcf-23c6216e443d

virtuallyunknown avatar Apr 01 '24 19:04 virtuallyunknown