Skip to content

Commit

Permalink
fix: update handwritten fastjson methods to avoid fallback to reflection
Browse files Browse the repository at this point in the history
Some handwritten fastjson methods were calling fastjson.Marshal with
the wrong types, leading to the library falling back to the slow
reflection-based marshaling logic.
  • Loading branch information
kruskall committed Jun 30, 2023
1 parent 60568a2 commit e32866e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions model/internal/modeljson/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ func (e *Exception) marshalOne(w *fastjson.Writer, offset, parentOffset int) (in
if len(e.Stacktrace) != 0 {
maybeComma()
w.RawString(`"stacktrace":`)
if err := fastjson.Marshal(w, e.Stacktrace); err != nil {
return -1, err
w.RawByte('[')
for i, v := range e.Stacktrace {
if i != 0 {
w.RawByte(',')
}
if err := v.MarshalFastJSON(w); err != nil {

Check failure on line 124 in model/internal/modeljson/error.go

View workflow job for this annotation

GitHub Actions / lint

v.MarshalFastJSON undefined (type StacktraceFrame has no field or method MarshalFastJSON)
return -1, err
}
}
w.RawByte(']')
}
w.RawByte('}')

Expand Down
2 changes: 1 addition & 1 deletion model/internal/modeljson/experience.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (u *UserExperience) MarshalFastJSON(w *fastjson.Writer) error {
w.RawByte(',')
}
w.RawString(`"longtask":`)
if err := fastjson.Marshal(w, u.Longtask); err != nil {
if err := u.Longtask.MarshalFastJSON(w); err != nil {

Check failure on line 64 in model/internal/modeljson/experience.go

View workflow job for this annotation

GitHub Actions / lint

u.Longtask.MarshalFastJSON undefined (type LongtaskMetrics has no field or method MarshalFastJSON)
return err
}
}
Expand Down

0 comments on commit e32866e

Please sign in to comment.