We have a json that is of 40kb, it takes around 200ms. If just reduced three fields in the json, the size reduced to 36kb but the response drops to 125ms on avg. We used json:"-" tags in the fields that we do not want to send. We are sending using
ctx.Status(fiber.StatusOK).JSON(model.GetEventListResponse{
Events: events,
NextPage: nextPage,
})
type GetEventListResponse struct {
NextPage string `json:"next_page"`
Events []Event `json:"events"`
}
type Event struct {
EventID int64 `json:"event_id"`
Currency int `json:"currency"`
EventName string `json:"event_name"`
Country string `json:"country"`
Place string `json:"place"`
EventFrom time.Time `json:"event_from"`
MainEventStart time.Time `json:"main_event_start"`
TotalParticipants int64 `json:"total_participants"`
TotalPool float64 `json:"total_pool"`
Laps int `json:"laps"`
TotalDistance float64 `json:"total_distance"`
SingleLapDistance float64 `json:"single_lap_distance"`
LapRecordTime time.Duration `json:"lap_record_time"`
LapRecordBy string `json:"lap_record_by"`
IsActive bool `json:"-"`
IsComplete bool `json:"-"`
Games []int64 `json:"-"`
}
The number of events are 100.
JSON Response:-
{
"next_page": "Pw0hLnA......................KK1f8bc9LIY=",
"events": [
{
"event_id": 202312181540001,
"currency": 64,
"event_name": "Event39",
"country": "Country39",
"place": "Place39",
"event_from": "2023-12-12T15:09:02.619Z",
"main_event_start": "2023-12-12T15:09:02.619Z",
"total_participants": 292,
"total_pool": 1676.4006608884679,
"laps": 28,
"total_distance": 876.2850461295575,
"single_lap_distance": 8.119311404702122,
"lap_record_time": 54542000000000,
"lap_record_by": "Racer39"
},....}
}
Have you tried using https://github.com/bytedance/sonic
I think you need to write benchmark tests that compare the performance of data marshaling with different encoders