Optimize repeated field decoding (#911)

Avoid allocating tear-off closures when decoding repeated but non-packed
fields.

Also refactors `BuilderInfo._decodeEnum`.

# Benchmarks

`repeated_int64`, `repeated_string`, and `repeated_enum` are the new
benchmarks added with this PR.

`fromBuffer` is an internal benchmark that decodes a large buffer.

`fromBufferUnmodifiableInput` is the same as `fromBuffer`, but the input
`Uint8List` is made unmodifiable.

## AOT

| | Before | After | Diff |

|-----------------------------|-----------|-----------|--------------------|
| repeated_int64 | 84,549 us | 61,820 us | -22,729 us, -25.8% |
| repeated_string | 67,183 us | 67,984 us | +801 us, +1.19% |
| repeated_enum | 52,335 us | 44,772 us | -7,563 us, -14.4% |
| fromBuffer | 25,661 us | 25,299 us | -362 us, -1.4% |
| fromBufferUnmodifiableInput | 26,135 us | 25,689 us | -446 us, -1.7% |

## JS

| | Before | After | Diff |

|-----------------------------|------------|------------|--------------------|
| repeated_int64 | 112,050 us | 109,850 us | -2,200 us, -1.9% |
| repeated_string | 123,050 us | 126,650 us | +3,600 us, +2.9% |
| repeated_enum | 43,920 us | 39,400 us | -4,520 us, -10.2% |
| fromBuffer | 211,888 us | 168,250 us | -43,638 us, -20.5% |
| fromBufferUnmodifiableInput | 227,444 us | 185,454 us | -41,990 us,
-18.4% |

---------

Co-authored-by: Ömer Sinan Ağacan <omersa@google.com>
3 files changed
tree: 53a48656ec83b40e3b0be5426e13fd84c889bd45
  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.