Skip to content

Commit

Permalink
Remove sync.Pool for relation-identifier buffers. (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenh authored Dec 11, 2024
1 parent fbbce07 commit 02ca521
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions pkg/ds/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bytes"
"strings"

"github.com/aserto-dev/azm/mempool"
"github.com/aserto-dev/azm/safe"
dsc3 "github.com/aserto-dev/go-directory/aserto/directory/common/v3"
dsr3 "github.com/aserto-dev/go-directory/aserto/directory/reader/v3"
Expand All @@ -15,10 +14,6 @@ import (
"github.com/rs/zerolog/log"
)

const maxRelationSize = 832

var bufPool = mempool.NewSlicePool[byte](maxRelationSize)

// Relation identifier.
type relation struct {
*safe.SafeRelation
Expand Down Expand Up @@ -60,10 +55,7 @@ func (i *relation) Key() []byte {
}

func (i *relation) ObjKey() []byte {
ptr := bufPool.Get()
defer bufPool.Put(ptr)

buf := bytes.NewBuffer(*ptr)
buf := newRelationBuffer()

buf.WriteString(i.GetObjectType())
buf.WriteByte(TypeIDSeparator)
Expand All @@ -86,10 +78,7 @@ func (i *relation) ObjKey() []byte {
}

func (i *relation) SubKey() []byte {
ptr := bufPool.Get()
defer bufPool.Put(ptr)

buf := bytes.NewBuffer(*ptr)
buf := newRelationBuffer()

buf.WriteString(i.GetSubjectType())
buf.WriteByte(TypeIDSeparator)
Expand Down Expand Up @@ -126,10 +115,7 @@ func (i *relation) PathAndFilter() ([]string, []byte, error) {
// format: obj_type : obj_id # relation @ sub_type : sub_id (# sub_relation).
// TODO: if subject relation exists add subject relation to filter clause.
func (i *relation) ObjFilter() []byte {
ptr := bufPool.Get()
defer bufPool.Put(ptr)

buf := bytes.NewBuffer(*ptr)
buf := newRelationBuffer()

buf.WriteString(i.GetObjectType())
buf.WriteByte(TypeIDSeparator)
Expand Down Expand Up @@ -163,10 +149,7 @@ func (i *relation) ObjFilter() []byte {
// format: sub_type : sub_id (# sub_relation) | obj_type : obj_id # relation.
// TODO: if subject relation exists add subject relation to filter clause.
func (i *relation) SubFilter() []byte {
ptr := bufPool.Get()
defer bufPool.Put(ptr)

buf := bytes.NewBuffer(*ptr)
buf := newRelationBuffer()

buf.WriteString(i.GetSubjectType())
buf.WriteByte(TypeIDSeparator)
Expand Down Expand Up @@ -363,3 +346,9 @@ func (i *relation) RelationValueFilter() (path bdb.Path, keyFilter []byte, value

return path, keyFilter, valueFilter
}

const maxRelationIdentifierSize = 384

func newRelationBuffer() *bytes.Buffer {
return bytes.NewBuffer(make([]byte, 0, maxRelationIdentifierSize))
}

0 comments on commit 02ca521

Please sign in to comment.