Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundant shallow copy when getting read-only map fields #741

Merged
merged 2 commits into from Aug 25, 2022

Conversation

osa1
Copy link
Member

@osa1 osa1 commented Aug 25, 2022

_FieldSet._$getMap unnecessarily shallow-copies the map field when the
message is read-only.

If a message is read-only then all of its fields are read-only, so the
map fields are read-only. We don't need to copy them.

Copying map fields on every access can be expensive depending on the map
size, so this will potentially be a significant performance win.

(Also, if we had to copy, we would have to deep-copy, rather than
shallow-copy, so the code would be buggy if we needed to copy the field)

Also fix _isReadonly field initialization in PbMap.unmodifiable.

We actually do not use PbMap.unmodifiable and we don't have any users
of it, but I think that method will be useful when fixing #705, so I'm
not removing it for now.

`_FieldSet._$getMap` unnecessarily shallow-copies the map field when the
message is read-only.

If a message is read-only then all of its fields are read-only, so the
map fields are read-only. We don't need to copy them.

Copying map fields on every access can be expensive depending on the map
size, so this will potentially be a significant performance win.

(Also, if we had to copy, we would have to deep-copy, rather than
shallow-copy, so the code would be buggy if we needed to copy the field)

Also fix `_isReadonly` field initialization in `PbMap.unmodifiable`.

We actually do not use `PbMap.unmodifiable` and we don't have any users
of it, but I think that method will be useful when fixing google#705, so I'm
not removing it for now.
@osa1 osa1 requested a review from sigurdm August 25, 2022 10:09
@osa1
Copy link
Member Author

osa1 commented Aug 25, 2022

I'll add changelog entries.

Copy link
Collaborator

@sigurdm sigurdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@osa1 osa1 merged commit 3ea789f into google:master Aug 25, 2022
@osa1 osa1 deleted the readonly_map_field branch August 25, 2022 10:25
osa1 added a commit to osa1/protobuf.dart that referenced this pull request Sep 15, 2022
osa1 added a commit that referenced this pull request Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants