Skip to content

Optimization allocations during Unmarshal #286

@prateek

Description

@prateek

Hey folks, thanks for a pretty bad ass library! I'm seeing a 3-3.3x gain when decoding fairly large JSON payloads (40-50MB) as compared stdlib/json-iterator.

Few things in the generated code that struck me as odd are the allocation sizes for slices/maps:

  • Slice is set to size 1 initially, values are appended using append
  • Map does not have a default size specified

Instead of this, I configured a static value for initial sizes for both slice/map, and changed the slice growth to always 2x the slice when len == cap (go's append will only 2x until 1024 and then it grows linearly. Each of the two sped things up by about 7% in my benchmarking.

I suggest the following changes to the library:

  1. Allow users to specify initial size for containers per key. Something like –
type Foo struct{
  bar []int `json:"bar","easyjson_initial_size:10"`
}
  1. Similarly allow users to either optionally specify (or always), do the 2x slice growth in the generated code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions