Keep a `ByteData` around in `CodedBufferReader` to avoid repeated `ByteData` allocs (#890)

In Dart, the only way to convert a list of bytes to an `int` or `double` is by using a `ByteData`.

Currently `CodedBufferReader` allocates a new `ByteData` for every fixed-size `int` or `float` decoding.

With this change we now allocate a `ByteData` once initialization and reuse it.

Benchmark results, using the same benchmark reported in #888:

|                              | Before     | After      | Diff                |
|------------------------------|------------|------------|---------------------|
| AOT                          |  26,763 us |  25,305 us | - 1,458 us, - 5.4%  |
| JIT                          |  24,573 us |  25,521 us | +   948 us, + 3.8%  |
| dart2js -O4                  | 212,000 us | 199,300 us | -12,700 us, - 5.9%  |
| dart2wasm --omit-type-checks |  89,750 us |  78,958 us | -10,792 us, -12.0%  |
1 file changed
tree: c9c5673f9b944bbd81bc64318c0c5b0e3393b1fc
  1. .github/
  2. api_benchmark/
  3. benchmarks/
  4. protobuf/
  5. protoc_plugin/
  6. tool/
  7. .gitignore
  8. analysis_options.yaml
  9. AUTHORS
  10. LICENSE
  11. mono_repo.yaml
  12. README.md
README.md

CI status

Protobuf support for Dart

Protocol Buffers (protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.

This repository is home to packages related to protobuf for Dart.

PackageDescriptionPublished Version
protobufA support library for the generated codepub package
protoc_pluginA Dart back-end for the protoc compilerpub package
api_benchmarkBenchmarking for various API calls
query_benchmarkBenchmark for encoding and decoding of a “real-world” protobuf

Publishing automation

For information about our publishing automation and release process, see https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.