google / google/protobuf.dart

Consider memoizing serialization of fields

Open
#722 1 comment 0 reactions 0 assignees View on GitHub
perf
Dominant language
Dart
Stars
572
Forks
196
Avg merge
1h 59m
Merged PRs (30d)
2

Description

I had this in mind for a while and today I realized that Java implementation actually does this: https://github.com/protocolbuffers/protobuf/blob/8d3a7327606b115dda871be54c8b8cb66d41ff90/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java#L110-L115

We could generalize the idea in the implementation above for JSON serialization as well.

This is somewhat related to #713. If I read a message but don't deserialize a field of it yet, I should be able to directly copy the bytes for the field to serialize, without having to deserialize it only to serialize it back.

One use case is when my app reads a large message, uses a few fields (maybe updates them, or just reads), and relays the message to some other app(s). For the message-fields that I don't modify I can directly copy the encoding to the relayed messages.

The main cost is memory to store the encodings, and an extra field to every field that can have memoized encoding.

Contributor guide

Open the contributing guide

Research direction

Start with the referenced Java LazyFieldLite.java implementation and the related issue #713; no Dart source file or test is named in this issue. Determine the intended scope for memoized field encodings and JSON serialization before identifying the affected runtime code. Done would require an agreed design and implementation plan, including the memory and compatibility trade-offs.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.