Skip to content

Freeze messages during parsing to avoid freeze pass #627

@osa1

Description

@osa1

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 (dart-lang/language#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    perfRelated to runtime performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions