1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00

778 Commits

Author SHA1 Message Date
Rob Figueiredo
11a37a0774 (*Stream).WriteMore: remove implicit Flush
I believe that WriteMore should not call Flush for these reasons:

1. This is surprising for users because of inconsistency. Why call Flush in
   WriteMore and not in WriteObjectEnd?

2. It is not necessary; callers are free to call Flush if their use case demands
   it.

3. It harms performance in the common case by flushing the buffer much more
   frequently than it needs to be flushed.

The stream benchmark shows a 7% benefit to removing the Flush call, and I
observed a similar speedup in my real-world use case.

    benchmark                                        old ns/op     new ns/op     delta
    Benchmark_encode_string_with_SetEscapeHTML-8     442           437           -1.13%
    Benchmark_jsoniter_large_file-8                  21222         21062         -0.75%
    Benchmark_json_large_file-8                      40187         40266         +0.20%
    Benchmark_stream_encode_big_object-8             8611          7956          -7.61%

    benchmark                                        old allocs     new allocs     delta
    Benchmark_encode_string_with_SetEscapeHTML-8     6              6              +0.00%
    Benchmark_jsoniter_large_file-8                  78             78             +0.00%
    Benchmark_json_large_file-8                      13             13             +0.00%
    Benchmark_stream_encode_big_object-8             0              0              +0.00%

    benchmark                                        old bytes     new bytes     delta
    Benchmark_encode_string_with_SetEscapeHTML-8     760           760           +0.00%
    Benchmark_jsoniter_large_file-8                  4920          4920          +0.00%
    Benchmark_json_large_file-8                      6640          6640          +0.00%
    Benchmark_stream_encode_big_object-8             0             0             +0.00%

Backwards compatibility - I believe there is little to no risk that this breaks
callers. WriteMore does not leave the JSON in a valid state, so it must be
followed by other Write* methods. To get the finished JSON out, the caller must
already be calling Flush.
2020-01-17 22:14:50 -05:00
Rob Figueiredo
91f4a6405d (*Stream).Flush: reset buffer to beginning
Previously it would append to the end of the buffer instead of reusing the
now-free space.

Benchmark demonstrates the improvement, run with -benchtime=10s

    benchmark                                        old ns/op     new ns/op     delta
    Benchmark_encode_string_with_SetEscapeHTML-8     447           442           -1.12%
    Benchmark_jsoniter_large_file-8                  20998         21222         +1.07%
    Benchmark_json_large_file-8                      39593         40187         +1.50%
    Benchmark_stream_encode_big_object-8             10787         8611          -20.17%

    benchmark                                        old allocs     new allocs     delta
    Benchmark_encode_string_with_SetEscapeHTML-8     6              6              +0.00%
    Benchmark_jsoniter_large_file-8                  78             78             +0.00%
    Benchmark_json_large_file-8                      13             13             +0.00%
    Benchmark_stream_encode_big_object-8             31             0              -100.00%

    benchmark                                        old bytes     new bytes     delta
    Benchmark_encode_string_with_SetEscapeHTML-8     760           760           +0.00%
    Benchmark_jsoniter_large_file-8                  4920          4920          +0.00%
    Benchmark_json_large_file-8                      6640          6640          +0.00%
    Benchmark_stream_encode_big_object-8             10056         0             -100.00%

Fixes #438
2020-01-17 21:57:59 -05:00
Rob Figueiredo
a54d350455 benchmarks: add benchmark for Stream 2020-01-17 16:50:46 -05:00
Tao Wen
49c900ee46
Merge pull request #427 from AllenX2018/fix-typo
fix the error message typo of ReadObjectCB & ReadMapCb function
2020-01-06 10:38:24 +08:00
allen
9c0685d8d3 fix the error message typo of ReadObjectCB & ReadMapCb function 2020-01-03 15:31:12 +08:00
Tao Wen
acfec88f7a
Merge pull request #422 from JensErat/map-invalid-type
pass nested error in compatible configuration, fixes #388
v1.1.9
2019-12-21 11:10:28 +08:00
Tao Wen
e88512faf8
Merge pull request #423 from vano144/fix-attachments-on-stream
fix nil attachment on stream in custom encoder on sorted map
2019-12-21 11:09:53 +08:00
Tao Wen
b681149eae
Merge pull request #424 from aaronbee/sortKeysMapAllocations
Reduce allocations in sortKeysMapEncoder
2019-12-21 11:09:15 +08:00
Tao Wen
d1af7639b3
Merge pull request #425 from liggitt/default-max-depth
Revert "Merge pull request #418 from bbrks/configurable_maxDepth"
2019-12-21 11:04:54 +08:00
Jordan Liggitt
7c9f8c2d20 Revert "Merge pull request #418 from bbrks/configurable_maxDepth"
This reverts commit 44a7e7340d23d2e5d5d942966eb683436c027da0, reversing
changes made to dc11f49689fd1c9a6de20749def70bd889bf0d42.
2019-12-19 19:06:29 -05:00
Aaron Beitch
f814d6c0f1 Reduce allocations in sortKeysMapEncoder
Use one buffer for all values.
2019-12-03 11:55:47 -08:00
Ivan Romanov
aba8654400 fix nil attachment on stream in custom encoder on sorted map 2019-11-28 17:39:42 +03:00
Jens Erat
a1c9557592
pass nested error in compatible configuration
When invalid types inside a map were marshalled (in general, as soon as
sorted maps have been configured), the error message has not been
propagated out of the map's `subStream`.

Also fix and re-enable the channel test, which now resembles the
behavior of `encoding/json` and tests both default and compatible
configurations.

Signed-off-by: Jens Erat <email@jenserat.de>
2019-11-22 16:56:59 +01:00
Tao Wen
44a7e7340d
Merge pull request #418 from bbrks/configurable_maxDepth
Add MaxDepth as a config option
2019-11-12 22:47:28 +08:00
Ben Brooks
2834c7e43c Remove large test values that fail on 32-bit architectures 2019-11-11 16:35:50 +00:00
Ben Brooks
d296277d5c Adds MaxDepth config option
Defaults to 10,000 to match the existing maxDepth constant everywhetre,
except when using `ConfigCompatibleWithStandardLibrary` - which retains
the limitless depth (and causes a stack overflow).

Added tests for the new config, and also up to jsoniter's stack overflow limit.
2019-11-11 16:13:59 +00:00
Tao Wen
dc11f49689
Merge pull request #416 from jarredhawkins/issue-415
Ignore unnamed literals in structs
2019-10-30 08:35:33 +08:00
Jarred Hawkins
83f7b825b3 Unnamed struct literals 2019-10-28 23:05:10 -07:00
Tao Wen
03217c3e97
Merge pull request #410 from liggitt/stack
Limit nesting depth
v1.1.8 1.1.8
2019-10-12 21:07:04 +08:00
Tao Wen
908eaed151
Merge pull request #408 from onelrdm/master
skip - tag before spliting parts
2019-10-12 21:05:04 +08:00
Jordan Liggitt
eec24895fe Limit nesting depth 2019-10-08 11:17:01 -04:00
onelrdm
1ba732a07d skip - tag before spliting parts 2019-09-28 17:17:44 +08:00
Tao Wen
819acad769
Merge pull request #398 from teou/master
use json.Marshaler then trim the last '\n' in reflect_marshaler
2019-09-23 14:02:24 +08:00
Tao Wen
695ec2b83b
Merge pull request #406 from bbrks/fix_nil_map_encoding
Fixes #405 - Encode nil map into null
2019-09-23 13:59:22 +08:00
Ben Brooks
028e2ef2bd Fixes #405 - Encode nil map into null 2019-09-19 13:11:30 +01:00
liyibo [李一博]
976454858b use json.Marshaler then trim the last '\n' in reflect_marshaler
N/A
2019-08-14 10:10:02 +08:00
Tao Wen
27518f6661
Merge pull request #373 from ernado/append-skip
fix #372: add AppendSkip iterator method
v1.1.7
2019-06-22 00:12:01 +08:00
Tao Wen
94869abf43
Merge pull request #368 from alextomaili/fix-memory-allocation-overhead
allocate string for error description only if it really required
2019-06-22 00:11:00 +08:00
Aleksandr Razumov
459f0e30ae
fix #37: add SkipAndAppendBytes iterator method 2019-06-10 12:40:05 +03:00
Tim Hockin
0039f4ac3d
Merge pull request #371 from nikhita/byte-base64-encode
Don't marshal empty byte or uint8 slice as null
2019-06-03 19:06:22 +02:00
Nikhita Raghunath
fb5614a4ca Don't marshal empty byte or uint8 slice as null
[]byte or []uint8 are encoded as base-64 encoded string. Per this, non-nil
empty slice should not get marshalled as null, rather as "".

This restores compatibility with the standard library.
2019-06-03 16:19:17 +05:30
alextomaili
f71b9090aa allocate string for error description only if it really required 2019-05-27 03:02:21 +03:00
Tao Wen
08047c174c fix #365, return error for +inf -inf and NaN 2019-05-23 13:57:43 +08:00
Tao Wen
68347ec4d6
Merge pull request #366 from stephen-obashitech/master
Fix typo in UnmarshalFromString documentation
2019-05-22 13:56:51 +08:00
Stephen Brown
0fd91468bb
Fix typo in UnmarshalFromString documentation 2019-05-21 12:48:31 +01:00
Tao Wen
1bc9828b4f
Merge pull request #361 from lggomez/master
Add go module definition
2019-05-19 23:23:02 +08:00
Luis GG
24c3d57281 Add go module definition 2019-04-25 17:40:48 -03:00
Tao Wen
0ff49de124 update README v1.1.6 2019-03-06 22:29:09 +08:00
Tao Wen
5bc9320502
Merge pull request #316 from proemergotech/master
fix #308 do NOT skip embedded structs without tag when OnlyTaggedFiel…
2019-02-08 15:56:42 +08:00
Tao Wen
f64ce68b6e
Merge pull request #338 from dvrkps/master
Clean go vet error and ineffassign warnings.
2019-01-14 23:53:30 +08:00
Tao Wen
2d42ff74dd
Merge pull request #337 from denverdino/fix-encode-with-MarshalJSON
Fix the incompatible encoding #336
2019-01-14 23:52:16 +08:00
Davor Kapsa
3a023a5fbc clean readPositiveFloat64 2019-01-10 18:00:15 +01:00
Davor Kapsa
16aef10b2b clean readPositiveFloat32 2019-01-10 17:55:28 +01:00
Davor Kapsa
ae4c002f78 rename ExampleMyKey 2019-01-10 17:51:25 +01:00
Li Yi
e4aa2ec063 Fix the incompatible encoding 2019-01-03 18:19:22 +08:00
Tao Wen
d05f387f50 fix #317, try parse as BigFloat if overflow 2018-11-12 14:45:56 +08:00
Adam Kiss
a9403d25cd fix #308 do NOT skip embedded structs without tag when OnlyTaggedField is set to true 2018-10-29 12:00:51 +01:00
Tao Wen
05d041de10 fix #313 support json marshaller type as map key 2018-10-24 23:28:41 +08:00
Tao Wen
5916df66b3 fix #311 handle nil any 2018-10-24 21:05:37 +08:00
Tao Wen
2433035e51
Merge pull request #304 from Quasilyte/quasilyte/emptyFallthrough
use multi-value case clause instead of fallthrough
2018-09-14 09:48:43 +08:00