-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
perf(util/gconv): add cache logic to enhance performance #3673
Conversation
2.修改或新增一些注释 3.删除无用代码
2.对doStruct的params参数增加map[string]any的快速判断,减少内存申请次数
… Improve/cache-gconv-struct
2.模糊匹配时增加一个字段来记录最后一次匹配到的key,加快匹配
2.增加bool和[]byte两个常见类型的转换函数
… Improve/cache-gconv-struct
@wln32 很棒的性能优化思路 👍 我刚粗略看了下,整体实现逻辑上没什么问题的,我需要仔细看看学习一下细节,需要花一点时间哈。 |
@wln32 Great performance optimization idea 👍 I just took a quick look at it, and there is nothing wrong with the overall implementation logic. I need to take a closer look at the details and spend some time. |
2.把convertStructInfo.fieldNamesMap修改为slice,可以加快速度
I'm still reviewing this. ❤️ |
…truct converting (#3) * fix(cmd/gf): fix command `gf up` with `-u` option upgrading packages indirectly required would fail with higher version of go required (gogf#3687) * up * up * refactor(util/gconv): add struct&field cache to improve performance for struct converting --------- Co-authored-by: 海亮 <[email protected]>
util/gconv/internal/structcache/structcache_cached_field_info.go
Outdated
Show resolved
Hide resolved
Quality Gate passedIssues Measures |
…hub.com:gogf/gf into feature/action-1.23 * 'feature/action-1.23' of github.com:gogf/gf: feat: version v2.7.3 (#3763) perf(util/gconv): add cache logic to enhance performance (#3673) fix(contrib/drivers/pgsql): fix insert error when data struct field has nil in PgSQL (#3679) fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732) fix(contrib/drivers/pgsql): #3671 fix invalid pgsql insert json type (#3742) refactor(nacos-registry): use official nacos sdk instead of the third-party nacos sdk (#3745) * 'feature/action-1.23' of github.com:gogf/gf: feat: version v2.7.3 (#3763) perf(util/gconv): add cache logic to enhance performance (#3673) fix(contrib/drivers/pgsql): fix insert error when data struct field has nil in PgSQL (#3679) fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732) fix(contrib/drivers/pgsql): #3671 fix invalid pgsql insert json type (#3742) refactor(nacos-registry): use official nacos sdk instead of the third-party nacos sdk (#3745)
gconv.Scan
,gconv.Struct
之类的函数(只要是转换到struct类型的)增加了缓存逻辑,不需要重复解析gconv.Int
,gconv.String
之类的,无需多次判断UseConvCacheExperiment
函数来控制,默认开启,如果开启后有什么bug,关闭即可,平稳过渡这么所的原因是当paramsMap的长度和结构体字段数量差距过大时,会造成一些不必要浪费
比如 以下代码
如果采用结构体字段map的长度来做循环,那么至少需要循环len(结构体字段map)次,即时使用一个额外的字段来统计赋值次数,在合适的时机退出,也不能保证赋值4次就可以退出,因为map的无序性,可能前三个字段一开始就匹配好了,最后一个ID字段可能在第七次才匹配到,中间几次没有匹配到,依然需要模糊匹配,所以这里以paramsMap的长度来做循环比较好
另外一种情况也是同样的
以下是本次的性能,会有一些浮动,