Skip to content

[dart2js] Sound null safety cleanup #60327

Open

Description

@rakudrama

Now that we no longer need to support legacy types:

  • Remove legacy type check helpers _asBoolS, _asIntS from impacts
    • Measure and report change in intermediate file sizes in modular compile
  • Remove legacy type check helpers from rti library
  • Replace uses options.useLegacySubtyping with false and simplify code
  • Remove class LegacyType
  • Remove Recipe.wrapStar and options.printLegacyStars

I'm interested in measuring the intermediate file sizes to see if BackenImpacts.newRtiImpact might be further simplified by omitting elements that are referenced from others.

Activity

  1. added
    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.
    P3A lower priority bug or feature request
    type-taskA well-defined stand-alone task
    on Mar 15, 2025
  2. biggs0125 commented on Mar 15, 2025

    @biggs0125

    @fishythefish Is already working on replacing dart2js's DartType with the CFE's so LegacyType will get removed as part of that change.

  3. rakudrama commented on Mar 17, 2025

    @rakudrama
    MemberAuthor

    I was wondering, for the purposes of assessing intermediate file size, if we have a script to run a modular compile?
    It seems that pkg/compiler/tools/modular_dart2js.dart no longer works.

  4. fishythefish commented on Mar 17, 2025

    @fishythefish
    Contributor

    I've had some CLs in the works to do some of this cleanup; I'm starting to send some of those out now. https://dart-review.googlesource.com/c/sdk/+/416024 in particular removes LegacyType without coupling it to the larger DartType cleanup.

    I'm also working on cleaning up SNS checks, but that requires some coordination with g3.

  5. self-assigned this
    on Mar 19, 2025
  6. fishythefish commented on Mar 19, 2025

    @fishythefish
    Contributor

    I compiled a certain large app (-O3, minification still enabled) at https://dart-review.googlesource.com/c/sdk/+/416160 and the CL immediately prior.

    Before removing the specializations, a sequential compilation looks like this:
    Running stage cfe...
    
    Compiled 327,303,689 input bytes (321,520,706 characters source) to 325,597,736 kernel bytes in 215 seconds using 6217.402 MB of memory
    Dart file reexported_main_sound.dart compiled to dill: old/out.dill.
    
    Running stage closed-world...
    
    Serialized 325,597,736 input bytes to 111,357,634 bytes data in 91.2 seconds using 5902.305 MB of memory
    Dart file old/out.dill serialized to data: old/world.data.
    
    Running stage global-inference...
    
    Serialized 436,955,370 bytes data to 46,629,537 bytes data in 104 seconds using 6393.316 MB of memory
    Data files old/out.dill and old/world.data serialized to data: old/global.data.
    
    Running stage codegen...
    
    Serialized 483,584,907 bytes data to 304,476,466 bytes data in 312 seconds using 8656.586 MB of memory
    Data files old/out.dill, old/world.data, and old/global.data serialized to codegen data: old/codegen0.
    
    Running stage emit-js...
    
    Compiled 788,061,373 bytes data to 51,991,836 characters JavaScript in 118 seconds using 6557.137 MB of memory
    
    After removing the specializations, it looks like this:
    Running stage cfe...
    
    Compiled 327,300,857 input bytes (321,519,232 characters source) to 325,596,248 kernel bytes in 214 seconds using 7023.699 MB of memory
    Dart file reexported_main_sound.dart compiled to dill: new/out.dill.
    
    Running stage closed-world...
    
    Serialized 325,596,248 input bytes to 111,357,142 bytes data in 90.9 seconds using 5917.559 MB of memory
    Dart file new/out.dill serialized to data: new/world.data.
    
    Running stage global-inference...
    
    Serialized 436,953,390 bytes data to 46,629,197 bytes data in 104 seconds using 6508.672 MB of memory
    Data files new/out.dill and new/world.data serialized to data: new/global.data.
    
    Running stage codegen...
    
    Serialized 483,582,587 bytes data to 304,472,915 bytes data in 315 seconds using 8804.633 MB of memory
    Data files new/out.dill, new/world.data, and new/global.data serialized to codegen data: new/codegen0.
    
    Running stage emit-js...
    
    Compiled 788,055,502 bytes data to 51,991,292 characters JavaScript in 118 seconds using 6561.238 MB of memory
    

    The input size diff is due to the 1474 characters removed from rti.dart.

    out.dill (the output of the cfe stage) is 1488 bytes smaller.
    world.data (the output of the closed-world stage) is 492 bytes smaller.
    global.data (the output of the global-inference stage) is 340 bytes smaller.
    codegen0 (the output of the codegen stage with a single shard) is 3551 bytes smaller.
    And we save 544 bytes of JS output.


    We can try the same thing on a minimal Dart program where we expect more tree-shaking (literally just void main() {}).

    Before removing specializations:
    Running stage cfe...
    
    Compiled 10,973,687 input bytes (5,190,704 characters source) to 5,043,848 kernel bytes in 1.71 seconds using 128.453 MB of memory
    Dart file main.dart compiled to dill: old/out.dill.
    
    Running stage closed-world...
    
    Serialized 5,043,848 input bytes to 187,429 bytes data in 1.05 seconds using 132.457 MB of memory
    Dart file old/out.dill serialized to data: old/world.data.
    
    Running stage global-inference...
    
    Serialized 5,231,277 bytes data to 50,545 bytes data in 1.01 seconds using 105.465 MB of memory
    Data files old/out.dill and old/world.data serialized to data: old/global.data.
    
    Running stage codegen...
    
    Serialized 5,281,822 bytes data to 251,149 bytes data in 1.74 seconds using 121.070 MB of memory
    Data files old/out.dill, old/world.data, and old/global.data serialized to codegen data: old/codegen0.
    
    Running stage emit-js...
    
    Compiled 5,532,971 bytes data to 4,833 characters JavaScript in 0.72 seconds using 94.941 MB of memory
    
    And after:
    Running stage cfe...                                                                                                                                                          
                                                                                                                                                                                  
    Compiled 10,970,855 input bytes (5,189,230 characters source) to 5,042,472 kernel bytes in 1.75 seconds using 128.953 MB of memory
    Dart file main.dart compiled to dill: new/out.dill.
    
    Running stage closed-world...
    
    Serialized 5,042,472 input bytes to 187,004 bytes data in 1.09 seconds using 132.957 MB of memory
    Dart file new/out.dill serialized to data: new/world.data.
    
    Running stage global-inference...
    
    Serialized 5,229,476 bytes data to 50,229 bytes data in 1.00 seconds using 100.328 MB of memory
    Data files new/out.dill and new/world.data serialized to data: new/global.data.
    
    Running stage codegen...
    
    Serialized 5,279,705 bytes data to 247,921 bytes data in 1.88 seconds using 120.570 MB of memory
    Data files new/out.dill, new/world.data, and new/global.data serialized to codegen data: new/codegen0.
    
    Running stage emit-js...
    
    Compiled 5,527,626 bytes data to 4,833 characters JavaScript in 0.74 seconds using 98.078 MB of memory
    

    The savings are similar but not identical.

  7. rakudrama commented on May 5, 2025

    @rakudrama
    MemberAuthor

    I want to leave this bug open as a place to record progress in by miscellaneous cleanup CLs.

  8. removed their assignment
    on May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-taskA well-defined stand-alone taskweb-dart2js

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions