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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to