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

Pre-allocate memory for slices to prevent repeated reallocation and copy during capacity expansion #103

Closed
dream-kzx opened this issue Jul 12, 2024 · 6 comments

Comments

@dream-kzx
Copy link
Contributor

func convertRetentionPolicy(queryResult *QueryResult) []RetentionPolicy {
var (
retentionPolicy = make([]RetentionPolicy, 0)
rpColumnLen = 8
)
if len(queryResult.Results) == 0 || len(queryResult.Results[0].Series) == 0 {
return retentionPolicy
}
for _, v := range queryResult.Results[0].Series[0].Values {
if len(v) < rpColumnLen {
break
}
var (
ok bool
replicaNum float64
)
rp := new(RetentionPolicy)
if rp.Name, ok = v[0].(string); !ok {
break
}
if rp.Duration, ok = v[1].(string); !ok {
break
}
if rp.ShardGroupDuration, ok = v[2].(string); !ok {
break
}
if rp.HotDuration, ok = v[3].(string); !ok {
break
}
if rp.WarmDuration, ok = v[4].(string); !ok {
break
}
if rp.IndexDuration, ok = v[5].(string); !ok {
break
}
if replicaNum, ok = v[6].(float64); !ok {
break
}
rp.ReplicaNum = int64(replicaNum)
if rp.IsDefault, ok = v[7].(bool); !ok {
break
}
retentionPolicy = append(retentionPolicy, *rp)
}
return retentionPolicy
}

variable: retentionPolicy

@hezhangjian
Copy link
Member

Although query retention policy isn't performance sensitive, but I think it can be optimized. #102 also reveals another problems of this class method. cc @cyruslo @Chenxulin97

@dream-kzx
Copy link
Contributor Author

There are many other places with the same problem. I've only listed this one.

@dream-kzx dream-kzx reopened this Jul 15, 2024
@Chenxulin97
Copy link
Member

There are many other places with the same problem. I've only listed this one.

It's not a problem , we will find the whole places and fix them . thanx for ur contribution.

@dream-kzx
Copy link
Contributor Author

ok

@hezhangjian
Copy link
Member

@dream-kzx Let's keep this issue open util it's resolved :)

@hezhangjian hezhangjian reopened this Jul 22, 2024
cyruslo added a commit to cyruslo/opengemini-client-go that referenced this issue Jul 23, 2024
cyruslo added a commit to cyruslo/opengemini-client-go that referenced this issue Jul 24, 2024
hezhangjian pushed a commit that referenced this issue Jul 24, 2024
Signed-off-by: cyruslo <710058301@qq.com>
@hezhangjian
Copy link
Member

closed by #117

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

No branches or pull requests

3 participants