Commit Graph

6 Commits

Author SHA1 Message Date
Jordan Liggitt
167dc75c19
Add omitzero support
Signed-off-by: Jordan Liggitt <liggitt@google.com>
2025-03-26 09:55:53 -04:00
Faye Amacker
9fa2077793 Replace interface{} with any
This commit replaces every instance of interface{} with any,
so go1.18 or newer is required to to build.
2025-02-22 14:05:53 -06:00
Faye Amacker
40e05c4d19
Remove build tag in encode_map.go 2025-02-22 12:39:23 -06:00
Ben Luddy
6396be350f
Refactor sorted map encode to use fewer buffers for nested maps.
Runs a bit faster, but more importantly, only needs a single buffer to encode nested, sorted maps
instead of using multiple temporary buffers.

                                                            │ before.txt  │             after.txt              │
                                                            │   sec/op    │   sec/op     vs base               │
MarshalCanonical/Go_map[string]string_to_CBOR_map_canonical   1.464µ ± 0%   1.395µ ± 0%  -4.68% (p=0.000 n=10)
MarshalCanonical/Go_map[int]int_to_CBOR_map_canonical         192.1n ± 0%   186.2n ± 1%  -3.10% (p=0.000 n=10)
geomean                                                       530.2n        509.6n       -3.89%

                                                            │ before.txt │               after.txt               │
                                                            │    B/op    │    B/op      vs base                  │
MarshalCanonical/Go_map[string]string_to_CBOR_map_canonical   88.00 ± 0%   112.00 ± 0%  +27.27% (p=0.000 n=10)
MarshalCanonical/Go_map[int]int_to_CBOR_map_canonical         3.000 ± 0%    3.000 ± 0%        ~ (p=1.000 n=10) ¹
geomean                                                       16.25         18.33       +12.82%
¹ all samples are equal

                                                            │ before.txt │              after.txt              │
                                                            │ allocs/op  │ allocs/op   vs base                 │
MarshalCanonical/Go_map[string]string_to_CBOR_map_canonical   2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
MarshalCanonical/Go_map[int]int_to_CBOR_map_canonical         1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                       1.414        1.414       +0.00%
¹ all samples are equal

Signed-off-by: Ben Luddy <bluddy@redhat.com>
2024-05-19 19:56:11 -04:00
Ben Luddy
8077474e3b
Remove encoderBuffer type in favor of using bytes.Buffer directly.
With its only remaining field being an embedded bytes.Buffer, there's no reason to retain the
encoderBuffer type.

Signed-off-by: Ben Luddy <bluddy@redhat.com>
2024-05-10 14:43:57 -04:00
Vu Dinh
380c17ea0b Use MapIter.SetKey/SetValue and sync.Pool to improve memory allocation
Since go 1.18, the reflect package introduces MapIter.SetKey and
MapIter.SetValue that will do fewer memory allocation for map
iteration which is frequently used for CBOR encode operation. Plus,
usage of sync.Pool will further reduce memory allocation by reusing
the shared memory in the pool. Lastly, the Value.SetZero method
(available since go 1.20) is helpful to release memory allocation
to the GC when is no longer needed.

Signed-off-by: Vu Dinh <vudinh@outlook.com>
2024-01-23 18:33:34 -05:00