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

no docs for what the dart compile js (dart2js) optimization levels are #51982

Closed
devoncarew opened this issue Apr 7, 2023 · 3 comments
Closed
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P3 A lower priority bug or feature request web-dart2js

Comments

@devoncarew
Copy link
Member

The docs for dart compile js mention that there are 4 output optimization levels, but don't provide any additional information to help choose between them. We should provide in-line descriptions of each level, or, link out to further documentation.

dart compile js -h
Compile Dart to JavaScript.

Usage: dart compile js [arguments] <dart entry point>
  -h, --help      Print this usage information (add -v for information about all options).
  -o, --output    Write the output to <file name>.
  -O<0,1,2,3,4>   Set the compiler optimization level (defaults to -O1).
@devoncarew devoncarew added the area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. label Apr 7, 2023
@sigmundch
Copy link
Member

Note that this is available providing the -v flag to the compiler (see that it is highlighted in the -h option):

dart compile js -v -h
...
  -O<0,1,2,3,4>
    Controls optimizations that can help reduce code-size and improve
    performance of the generated code for deployment.

    -O0
       Disables all optimizations. Equivalent to calling dart2js with these
       extra flags:
        --disable-inlining
        --disable-type-inference
        --disable-rti-optimizations


       Some optimizations cannot be dissabled at this time, as we add the option
       to disable them, they will be added here as well.

    -O1
       Enables default optimizations. Equivalent to calling dart2js with no
       extra flags.

    -O2
       Enables optimizations that respect the language semantics and are safe
       for all programs. It however changes the string representation of types,
       which will no longer be consistent with the Dart VM or DDC.

       Equivalent to calling dart2js with these extra flags:
        --minify
        --lax-runtime-type-to-string
        --omit-late-names

    -O3
       Enables optimizations that respect the language semantics only on
       programs that do not ever throw any subtype of `Error`.  These
       optimizations improve the generated code, but they may cause programs to
       behave unexpectedly if this assumption is not met.  To use this
       option, we recommend that you properly test your application first
       without it, and ensure that no subtype of `Error` (such as `TypeError`)
       is ever thrown.

       Equivalent to calling dart2js with these extra flags:
         -O2
         --omit-implicit-checks

    -O4
       Enables more aggressive optimizations than -O3, but with the same
       assumptions. These optimizations are on a separate group because they
       are more susceptible to variations in input data. To use this option we
       recommend to pay special attention to test edge cases in user input.

       Equivalent to calling dart2js with these extra flags:
         -O3
         --trust-primitives

    While some of the individual optimizations and flags may change with time,
    we intend to keep the -O* flags stable. New safe optimizations may be added
    on any level, and optimizations that only work on some programs may move up
    from one level to the next (for instance, once alternative safe
    optimizations are implemented, `omit-implicit-checks` may be removed or may
    move to the O4 level).

@devoncarew
Copy link
Member Author

Ah, gotcha. I wasn't clear to me that re-running w/ -v would show that info. Perhaps add single line summaries to the regular help output? Or, have some verbiage to say re-running with -v will show information about the optimization levels?

@sigmundch
Copy link
Member

Seems like the comment next to -h is easy to miss, correct? What if we move that up and say it upfront (rather than next to one flag)?

@sigmundch sigmundch added web-dart2js P3 A lower priority bug or feature request area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. and removed area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. labels Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P3 A lower priority bug or feature request web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants