Skip to content

Conversation

@osa1
Copy link
Member

@osa1 osa1 commented Sep 4, 2025

(This is cl/658131451 ported to open source, not my CL)

CL description: (slightly edited)

This is a generated-code size optimization.

The main change is to generate the valueOf functions for protobuf enums programatically, rather than (1) use the per-enum FooPbEnum.valueOf static function tear-foo which (2) uses a per-enum static variable that is lazily initialized to map from int value to the protobuf enum value.

With ~1000 protobuf enums, this allows most of the valueOf static function tear-off closures to tree-shaken, together with their functions and the code for the initializer of the map.

The secondary change is to use more specialized 'add' methods to BuilderInfo, allowing many fields to be 'defined' with a call with fewer arguments.

Together, these changes reduce the size of the main unit of an app by about 1.3%, and would have a similar effect on native targets.

This change requires dart-lang/sdk@175dc05, which was released with Dart 3.6.0.

@osa1 osa1 requested a review from sigurdm September 4, 2025 10:15
@github-actions
Copy link

github-actions bot commented Sep 4, 2025

Package publishing

Package Version Status Publish tag (post-merge)
package:protobuf 5.0.0 (error) pubspec version (5.0.0) and changelog (5.0.0-wip) don't agree
package:protoc_plugin 23.0.0 ready to publish protoc_plugin-v23.0.0

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@osa1 osa1 changed the title Sync cl/658131451 Use a map to cache the valueOf function for enums Sep 4, 2025
@osa1 osa1 changed the title Use a map to cache the valueOf function for enums Use a map to cache the valueOf functions for enums Sep 4, 2025
@osa1 osa1 merged commit 971bcae into google:master Sep 8, 2025
11 of 12 checks passed
@osa1 osa1 deleted the cl658131451 branch September 8, 2025 09:20
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Sep 9, 2025
Revisions updated by `dart tools/rev_sdk_deps.dart`.

ai (https://github.com/dart-lang/ai/compare/1547a83..bc90433):
  bc90433  2025-09-04  Greg Spencer  Add pub add format guidance (dart-lang/ai#278)
  845c126  2025-09-04  dependabot[bot]  Bump the github-actions group with 2 updates (dart-lang/ai#277)
  5568958  2025-09-04  Jacob MacDonald  add a GEMINI.md file (dart-lang/ai#279)

core (https://github.com/dart-lang/core/compare/5c3e2c3..a4dc873):
  a4dc8738  2025-09-09  Ömer Sinan Ağacan  Implement `Int64` as a wrapper for `int` when targeting native and Wasm (dart-lang/core#905)
  1aa58ef5  2025-09-08  Devon Carew  [fixnum] update the min. required dart sdk (dart-lang/core#907)
  60f2b5d3  2025-09-08  Ömer Sinan Ağacan  Run fixnum tests with dart2wasm (dart-lang/core#906)

dartdoc (https://github.com/dart-lang/dartdoc/compare/53222e2..efff7c1):
  efff7c1f  2025-09-08  Sarah Zakarias  Remove  runtime_renderers.dart (dart-lang/dartdoc#4101)
  4e2daf57  2025-09-05  Sarah Zakarias  Rename LanguageFeature and remove FeatureSet mixin (dart-lang/dartdoc#4099)
  ecc48d00  2025-09-02  dependabot[bot]  Bump the github-actions group across 1 directory with 3 updates (dart-lang/dartdoc#4098)

protobuf (https://github.com/dart-lang/protobuf/compare/0a13935..971bcae):
  971bcae  2025-09-08  Ömer Sinan Ağacan  Use a map to cache the `valueOf` functions for enums (google/protobuf.dart#1047)
  8750ed7  2025-09-05  Ömer Sinan Ağacan  Sync internal Kythe support improvements (google/protobuf.dart#1048)

web (https://github.com/dart-lang/web/compare/a152054..e2daa3a):
  e2daa3a  2025-09-04  Nikechukwu  [interop] Add support for Intersection types (dart-lang/web#451)

webdev (https://github.com/dart-lang/webdev/compare/52ad019..23aefeb):
  23aefebe  2025-09-05  jensjoha  Fix CI flake in dwds/test/hot_restart_breakpoints_test.dart (dart-lang/webdev#2685)

Change-Id: I36cfbcdd884e8e0e38e24a9c7f3bcfcc15fdd9ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449000
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
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.

2 participants