某个文件下vscode代码提示变得非常慢/Code Autocompletion Slowed Down in a Specific VSCode File

某个文件下vscode代码提示变得非常慢

前段时间在工作中发现,使用vscode在某个文件下(tsx格式),代码提示突然变得特别慢,非常影响开发效率,最后排查到了问题并顺利解决,现在记录一下排查思路。

首先,为了排除插件的干扰,先禁用掉了所有的vscode插件,如果禁用之后问题解决,再一个一个的放开,确定是哪个插件的问题。

在禁用全部插件之后代码提示还是非常的慢,接着我又把文件顶部所有的import语句全部注释了,注释之后发现不卡了,代码提示恢复了正常!所以看起来应该是某个import语句导致了提示变慢,然后开始一个一个的import放开,最后发现在放开

import { Member } from '../../../interfaces/MemberInterface';

这行import之后,伴随着风扇一阵呼呼声,代码提示又变慢了。。后面慢慢排查了一下,发现Member类型和 react-hook-form 同时放开代码提示就会变慢

import { Controller, FormProvider, useForm } from 'react-hook-form';
import { Member } from '../../../interfaces/MemberInterface';

猜测是因为我们项目里的Member类型有非常多的字段,而且还有不少嵌套字段,而 react-hook-form 内部又对表单类型做了很复杂的操作,所以让整个页面的代码提示一下变慢了

不清楚这算不算react-hook-form的bug,或者就不应该使用Member类型来定义表单字段,也许memberId就够了(string) 请帮我把这篇文章翻译为英语版本,请保留我的markdown语法

Code Autocompletion Slowed Down in a Specific VSCode File

Recently, I encountered a sudden slowdown in code autocompletion in a TypeScript (.tsx) file while working in VSCode. This issue significantly affected my development efficiency. After thorough investigation, I managed to identify the problem and resolve it. Here, I’ll document the troubleshooting process.

To eliminate the possibility of plugin interference, I began by disabling all VSCode extensions. If disabling them resolved the issue, I planned to re-enable them one by one to pinpoint the problematic extension.

Even after disabling all extensions, the code autocompletion remained sluggish. I then commented out all the import statements at the top of the file. Surprisingly, after this change, the lag disappeared, and code autocompletion returned to normal. This suggested that a specific import statement was causing the slowdown. I began re-enabling import statements one by one and discovered that the code autocompletion became slow again when I enabled the following import:

import { Member } from '../../../interfaces/MemberInterface';

As soon as I allowed this import, my computer’s fan kicked into high gear, and code autocompletion slowed down once more. Upon further investigation, I found that the Member type in our project had numerous fields and nested structures. Additionally, react-hook-form performs complex operations on form types, which seemed to be the root of the issue.

import { Controller, FormProvider, useForm } from 'react-hook-form';
import { Member } from '../../../interfaces/MemberInterface';

It appeared that the combination of the extensive Member type and react-hook-form operations was causing the code autocompletion slowdown. It’s unclear whether this issue qualifies as a bug in react-hook-form or whether it’s advisable to define form fields using a simplified type, such as memberId (type string) instead of Member.

发表评论

您的电子邮箱地址不会被公开。