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
enhance: improve gf gen service using AST #3488
base: master
Are you sure you want to change the base?
Conversation
这块逻辑比较复杂,需要花点时间 |
This logic is relatively complex and will take some time to |
@oldme-git 我在项目中执行了一下,遇到生成方法重复的问题。我把文件作为附件上传,你可以尝试一下,建议加上一个类似的单例在提交代码中。 打包的 |
单测已经加上了。生成文件的那一块也整理了一下,去掉了因为正则不准确而又多添加的矫正代码。另外,在生成文件的地方进行了两个优化:
最终性能得到了约 正则 AST 在测试中,大部分的时间都用来 |
Single test has been added. The generated file has also been tidied up, and the correction code added due to inaccurate regular expressions has been removed. In addition, two optimizations have been made where the file is generated:
The final performance was improved by about regular AST In testing, most of the time is spent generating good files with |
Review Dear:
本次 PR 对
gf gen service
进行了部分重构,即使用AST
替换Regex
来解析logic
文件。因为gf gen是一个比较重要功能,反馈的问题也比较多,所以此次提交比较重要!性能方面
相较于多次正则不同,
AST
可一次循环解析出所有需要的语法,例如import, func, param, comment
,所以性能得到了略微的提升。以下是对1000个文件,若干方法的测试结果,单位秒,测试环境:go1.22.1 windows11/AMD Ryzen 5500U/16G memory
AST 三次:
Regex 三次:
测试文件和方法:click me
改动简述
gf-cli
所需的数据;service
;CGenService.Service
方法的部分重构,用以适应新的逻辑fixed #3067
fixed #3492
fixed #2310
fixed #3104
fixed #3434
fixed #3474