google / google/protobuf.dart

Freeze messages during parsing to avoid freeze pass

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

Description

Currently if I use a message in read-only way I need to first parse it, then do a pass to freeze it.

If we had a way of generating frozen (read-only) messages in parsers that would eliminate the extra pass for freezing.

Implementation should be trivial, but extending the generated message API in a backwards-compatible way will be sub-optimal because we can't mix optional positional and named arguments (https://github.com/dart-lang/language/issues/1076).

If mixing positional and named optionals were allowed we could extend the `fromBuffer` and other parse methods with an optional named argument `{bool freeze = false}`. Since this is not possible yet we will need to add a new constructor like `fromBufferReadOnly` (or `fromBufferFrozen`, and another one for parsing JSON). With luck these extra constructors will be tree-shaken when not used and won't cause binary size issues in JS and AOT.

I'm looking at internal users to see if freezing right after parsing is a common pattern.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the generated message parsing entry points, especially fromBuffer and the JSON parsing methods, then inspect the internal users mentioned in the issue for freeze-after-parse patterns. Done means parsers can produce frozen messages without a separate freezing pass while preserving backwards compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.