diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2016-11-10 16:38:04 -0800 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2016-11-10 18:14:05 -0800 |
commit | bd158fc23849663f1cdb430ddea2dbab9deb336f (patch) | |
tree | 3b34e3fa84a82efb1fa7b685cf826ce0b52bc93e /src/google/protobuf/util/json_util.h | |
parent | df8390790aae6025e95687a37eea81a4757966d0 (diff) | |
download | protobuf-bd158fc23849663f1cdb430ddea2dbab9deb336f.tar.gz protobuf-bd158fc23849663f1cdb430ddea2dbab9deb336f.tar.bz2 protobuf-bd158fc23849663f1cdb430ddea2dbab9deb336f.zip |
Speed up JSON parsing.
It turns out calling StringOutputStream::Next()/BackUp() repeatedly is
very costly in opensource protobuf because it keeps resize() the string
back and forth. The current JSON conversion API suffers this problem and
leads to ridiculously long parsing time:
https://github.com/google/protobuf/issues/2305#issuecomment-257785492
This change fixes the problem but caching the buffer of Next() and avoid
calling BackUp() as much as possible.
Diffstat (limited to 'src/google/protobuf/util/json_util.h')
-rw-r--r-- | src/google/protobuf/util/json_util.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h index 6d3cee52..0e45ef81 100644 --- a/src/google/protobuf/util/json_util.h +++ b/src/google/protobuf/util/json_util.h @@ -172,12 +172,15 @@ namespace internal { class LIBPROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink { public: explicit ZeroCopyStreamByteSink(io::ZeroCopyOutputStream* stream) - : stream_(stream) {} + : stream_(stream), buffer_size_(0) {} + ~ZeroCopyStreamByteSink(); virtual void Append(const char* bytes, size_t len); private: io::ZeroCopyOutputStream* stream_; + void* buffer_; + int buffer_size_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyStreamByteSink); }; |