Merge pull request #101 from mraleph/speedup

Rewrite CodedBufferWriter to speed it up.

The previous implementation was allocating two typed arrays per each written
varint and was using maps to lookup writer functions and wire types for
different field types.

After the rewrite we instead maintain two arrays:

an array of Uint8List chunks, which serve as temporary output buffers for
small data (ints and floats);
an array of splices which describes additional bytes to splice in-between
bytes written into chunks.
Note that it is impossible to serialize protobufs in a purely streaming fashion
(using a single continuous output buffer) because some values are serialized
in length-deliminted format - meaning that they are represented as a
varint encoded length followed by the specified number of bytes of data. This
in turn means that we sometimes have to write data before we know how
much space needs to be reseved for the length of the data.

Additionally in some cases value is a raw sequence of bytes that needs to be
written as-is into the output buffer - in this case it does not make sense to
first copy this data into temporary buffer and then copy it again.

These two considerations lead to the splice based design described above.

On my machine this change improves ToBinary benchmark by ~4x both on the VM and on V8 after dart2js compilation. The size of the JavaScript generated from benchmark_js.dart is 1% smaller.
tree: c47ce40e4a4405efc119be3a95e871530c3f3bca
  1. benchmarks/
  2. lib/
  3. test/
  4. .gitignore
  5. .status
  6. .test_config
  7. .travis.yml
  8. analysis_options.yaml
  9. AUTHORS
  10. CHANGELOG.md
  11. codereview.settings
  12. CONTRIBUTING.md
  13. LICENSE
  14. pubspec.yaml
  15. README.md
README.md

Build Status pub package

Provides runtime support for a Dart implementation of protobufs.

Typically one do not need to import this library–only libraries generated by the protoc plugin import this library directly.

If your library or application uses generated protobuf libraries, add this library as a dependency.

References