You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "shibd (via GitHub)" <gi...@apache.org> on 2023/06/29 09:38:45 UTC
[GitHub] [pulsar-client-go] shibd commented on a diff in pull request #1033: [Improve] improve the perf of schema and schema cache
shibd commented on code in PR #1033:
URL: https://github.com/apache/pulsar-client-go/pull/1033#discussion_r1246387681
##########
pulsar/schema.go:
##########
@@ -66,13 +67,21 @@ type SchemaInfo struct {
Schema string
Type SchemaType
Properties map[string]string
+ hashVal atomic.Uint64
}
-func (s SchemaInfo) hash() uint64 {
+func (s *SchemaInfo) hash() uint64 {
+ oldHash := s.hashVal.Load()
+ if oldHash != 0 {
+ return oldHash
+ }
+
h := maphash.Hash{}
h.SetSeed(seed)
h.Write([]byte(s.Schema))
- return h.Sum64()
+ newHash := h.Sum64()
+ s.hashVal.CompareAndSwap(oldHash, newHash)
Review Comment:
We can use `sync.Once` to ensure `hashVal` just set value on first call time.
``` go
s.onc.Do(func() {
h := maphash.Hash{}
h.SetSeed(seed)
h.Write([]byte(s.Schema))
s.hashVal = h.Sum64()
})
return s.hashVal
```
##########
pulsar/schema.go:
##########
@@ -37,27 +38,27 @@ import (
type SchemaType int
const (
- NONE SchemaType = iota //No schema defined
Review Comment:
Please do not submit format changes that are not related to this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org