Skip to content
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

refactor(cmd/gf): improve command gf gen ctrl using ast #3470

Merged
merged 5 commits into from
Apr 11, 2024

Conversation

oldme-git
Copy link
Member

@oldme-git oldme-git commented Apr 10, 2024

Dear review:
使用AST替换正则,使用buf来优化性能,经过对1000个文件扫描重新生成后,两者速度几乎一致。
以下是我的测试结果:

AST 三次
6.8575744
6.7882356
6.4620533
正则三次
6.5929272
6.178121
6.2337657

单位都为秒,测试环境:go1.22.1 windows11/AMD Ryzen 5500U/16G memory

测试仓库,可以直接拉下来测试:
AST 测试仓库:click me
正则测试仓库(master):click me

执行 TestPerformance 方法,即可看见测试结果。如果此 PR 被社区接受,后续会进行正则全部替换成AST的工作。
此外,单测为什么需要修改?
因为 AST 遍历出来的结构体名称是乱序的,所以不能单纯的只使用文件内容比较。

fixed #3067

@oldme-git oldme-git added the wip label Apr 10, 2024
@oldme-git oldme-git added wip and removed wip labels Apr 10, 2024
@oldme-git oldme-git removed the wip label Apr 10, 2024
cmd/gf/internal/utility/ast/ast.go Outdated Show resolved Hide resolved
cmd/gf/internal/utility/ast/ast.go Outdated Show resolved Hide resolved
@gqcn gqcn changed the title gf gen ctrl use AST to get original info enhance: improve gf gen ctrl using AST Apr 10, 2024
@oldme-git oldme-git requested a review from gqcn April 11, 2024 07:44
@gqcn gqcn merged commit 2523889 into gogf:master Apr 11, 2024
23 checks passed
@oldme-git oldme-git deleted the AST branch April 24, 2024 08:36
@gqcn gqcn changed the title enhance: improve gf gen ctrl using AST refactor(cmd/gf): improve command gf gen ctrl using ast Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(超级月经贴) Should use AST code refactoring some gf gen commands.
2 participants