diff --git a/pulsar/producer_partition.go b/pulsar/producer_partition.go index fc67f51581..6c2547bb9e 100644 --- a/pulsar/producer_partition.go +++ b/pulsar/producer_partition.go @@ -101,12 +101,12 @@ type partitionProducer struct { type schemaCache struct { lock sync.RWMutex - schemas map[string][]byte + schemas map[uint64][]byte } func newSchemaCache() *schemaCache { return &schemaCache{ - schemas: make(map[string][]byte), + schemas: make(map[uint64][]byte), } } @@ -122,9 +122,9 @@ func (s *schemaCache) Get(schema *SchemaInfo) (schemaVersion []byte) { s.lock.RLock() defer s.lock.RUnlock() - key := schema.hash() - return s.schemas[key] + return s.schemas[schema.hash()] } + func newPartitionProducer(client *client, topic string, options *ProducerOptions, partitionIdx int, metrics *internal.LeveledMetrics) ( *partitionProducer, error) { diff --git a/pulsar/schema.go b/pulsar/schema.go index 405049dcee..0b413d40a6 100644 --- a/pulsar/schema.go +++ b/pulsar/schema.go @@ -19,10 +19,9 @@ package pulsar import ( "bytes" - "crypto/sha256" - "encoding/hex" "encoding/json" "fmt" + "hash/maphash" "reflect" "unsafe" @@ -69,10 +68,11 @@ type SchemaInfo struct { Properties map[string]string } -func (s SchemaInfo) hash() string { - h := sha256.New() +func (s SchemaInfo) hash() uint64 { + h := maphash.Hash{} + h.SetSeed(seed) h.Write([]byte(s.Schema)) - return hex.EncodeToString(h.Sum(nil)) + return h.Sum64() } type Schema interface { @@ -183,6 +183,8 @@ type ProtoSchema struct { SchemaInfo } +var seed = maphash.MakeSeed() + // NewProtoSchema creates a new ProtoSchema // Note: the function will panic if creation of codec fails func NewProtoSchema(protoAvroSchemaDef string, properties map[string]string) *ProtoSchema {