Skip to content

Commit

Permalink
Reset ArenaPool after use
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-imx committed Aug 3, 2023
1 parent df37ddd commit 90249b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion structs_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var defaultArena fastjson.ArenaPool
// MarshalJSON implements the marshal interface
func (l *Log) MarshalJSON() ([]byte, error) {
a := defaultArena.Get()
defer a.Reset()

o := a.NewObject()
if l.Removed {
Expand Down Expand Up @@ -46,6 +47,7 @@ func (t *Block) MarshalJSON() ([]byte, error) {
}

a := defaultArena.Get()
defer a.Reset()

o := a.NewObject()
o.Set("number", a.NewString(fmt.Sprintf("0x%x", t.Number)))
Expand Down Expand Up @@ -97,6 +99,8 @@ func (t *Block) MarshalJSON() ([]byte, error) {
// MarshalJSON implements the Marshal interface.
func (t *Transaction) MarshalJSON() ([]byte, error) {
a := defaultArena.Get()
defer a.Reset()

v := t.marshalJSON(a)
res := v.MarshalTo(nil)
defaultArena.Put(a)
Expand Down Expand Up @@ -179,6 +183,7 @@ func (t *AccessList) marshalJSON(a *fastjson.Arena) *fastjson.Value {
// MarshalJSON implements the Marshal interface.
func (c *CallMsg) MarshalJSON() ([]byte, error) {
a := defaultArena.Get()
defer a.Reset()

o := a.NewObject()
o.Set("from", a.NewString(c.From.String()))
Expand Down Expand Up @@ -206,6 +211,7 @@ func (c *CallMsg) MarshalJSON() ([]byte, error) {
// MarshalJSON implements the Marshal interface.
func (l *LogFilter) MarshalJSON() ([]byte, error) {
a := defaultArena.Get()
defer a.Reset()

o := a.NewObject()
if len(l.Address) == 1 {
Expand Down Expand Up @@ -257,6 +263,7 @@ func (l *LogFilter) MarshalJSON() ([]byte, error) {

func (s StateOverride) MarshalJSON() ([]byte, error) {
a := defaultArena.Get()
defer a.Reset()

o := a.NewObject()
for addr, obj := range s {
Expand Down Expand Up @@ -291,4 +298,4 @@ func (s StateOverride) MarshalJSON() ([]byte, error) {
defaultArena.Put(a)

return res, nil
}
}

0 comments on commit 90249b1

Please sign in to comment.