```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(socket): 优化TCP连接处理性能

- 添加最小可读长度检查,避免无效Peek操作
- 修复数据部分解析逻辑,避免空切片分配

perf(utils): 优化并发哈希映射性能

- 将分段数量调整为CPU核心数
- 重写Range方法,移除channel和goroutine开销
- 添加原子标志控制遍历终止

perf(utils): 优化结构体序列化缓存机制

- 添加sync.Map缓存预处理结果
- 支持结构体、自定义类型、二进制类型分别缓存
- 减少重复反射
This commit is contained in:
昔念
2026-02-22 10:59:41 +08:00
parent 790bc21034
commit 1dc75b529d
5 changed files with 159 additions and 78 deletions

View File

@@ -14,16 +14,15 @@ type MonsterRefresh struct {
MapID int32 `gorm:"not null;comment:'地图ID'" json:"map_id"`
// 坑位绑定配置(支持多坑位绑定,循环刷新)
PitID1 []int32 `gorm:"type:int8[];not null;comment:'坑位1绑定的坑位ID列表多绑循环刷'" json:"pit_id_1"`
PitID2 []int32 `gorm:"type:int8[];not null;comment:'坑位2绑定的坑位ID列表多绑循环刷'" json:"pit_id_2"`
PitID3 []int32 `gorm:"type:int8[];not null;comment:'坑位3绑定的坑位ID列表多绑循环刷'" json:"pit_id_3"`
PitID4 []int32 `gorm:"type:int8[];not null;comment:'坑位4绑定的坑位ID列表多绑循环刷'" json:"pit_id_4"`
PitID5 []int32 `gorm:"type:int8[];not null;comment:'坑位5绑定的坑位ID列表多绑循环刷'" json:"pit_id_5"`
PitID6 []int32 `gorm:"type:int8[];not null;comment:'坑位6绑定的坑位ID列表多绑循环刷'" json:"pit_id_6"`
PitID7 []int32 `gorm:"type:int8[];not null;comment:'坑位7绑定的坑位ID列表多绑循环刷'" json:"pit_id_7"`
PitID8 []int32 `gorm:"type:int8[];not null;comment:'坑位8绑定的坑位ID列表多绑循环刷'" json:"pit_id_8"`
PitID9 []int32 `gorm:"type:int8[];not null;comment:'坑位9绑定的坑位ID列表多绑循环刷'" json:"pit_id_9"`
PitID1 []int32 `gorm:"type:int[];not null;comment:'坑位1绑定的坑位ID列表多绑循环刷'" json:"pit_id_1"`
PitID2 []int32 `gorm:"type:int[];not null;comment:'坑位2绑定的坑位ID列表多绑循环刷'" json:"pit_id_2"`
PitID3 []int32 `gorm:"type:int[];not null;comment:'坑位3绑定的坑位ID列表多绑循环刷'" json:"pit_id_3"`
PitID4 []int32 `gorm:"type:int[];not null;comment:'坑位4绑定的坑位ID列表多绑循环刷'" json:"pit_id_4"`
PitID5 []int32 `gorm:"type:int[];not null;comment:'坑位5绑定的坑位ID列表多绑循环刷'" json:"pit_id_5"`
PitID6 []int32 `gorm:"type:int[];not null;comment:'坑位6绑定的坑位ID列表多绑循环刷'" json:"pit_id_6"`
PitID7 []int32 `gorm:"type:int[];not null;comment:'坑位7绑定的坑位ID列表多绑循环刷'" json:"pit_id_7"`
PitID8 []int32 `gorm:"type:int[];not null;comment:'坑位8绑定的坑位ID列表多绑循环刷'" json:"pit_id_8"`
PitID9 []int32 `gorm:"type:int[];not null;comment:'坑位9绑定的坑位ID列表多绑循环刷'" json:"pit_id_9"`
}
type MonsterRefreshEX struct {
@@ -51,49 +50,6 @@ func NewMonsterRefresh() *MonsterRefresh {
}
}
// GetAllPitIDs 获取所有9个坑位的绑定ID列表辅助方法便于批量处理
func (m *MonsterRefresh) GetAllPitIDs() [9][]int32 {
return [9][]int32{
m.PitID1,
m.PitID2,
m.PitID3,
m.PitID4,
m.PitID5,
m.PitID6,
m.PitID7,
m.PitID8,
m.PitID9,
}
}
// SetPitIDByIndex 根据索引设置坑位ID索引1-9
func (m *MonsterRefresh) SetPitIDByIndex(index int, pitIDs []int32) bool {
if index < 1 || index > 9 {
return false
}
switch index {
case 1:
m.PitID1 = pitIDs
case 2:
m.PitID2 = pitIDs
case 3:
m.PitID3 = pitIDs
case 4:
m.PitID4 = pitIDs
case 5:
m.PitID5 = pitIDs
case 6:
m.PitID6 = pitIDs
case 7:
m.PitID7 = pitIDs
case 8:
m.PitID8 = pitIDs
case 9:
m.PitID9 = pitIDs
}
return true
}
// init 初始化表结构(程序启动时自动创建/同步表)
func init() {
cool.CreateTable(&MonsterRefresh{})