-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Profile gn gen
and no-op engine builds.
#81074
Comments
Ok, that was easier than I expected. As anticipated, it was script execution. A couple of the scripts, we can get rid of and use GN built-ins. There are some that can be parallelized. Generating Xcode projects can also probably be opt-in. Adding |
The ios_sdk.py and mac_sdk.gni bottlenecks can be tackled by being smarter about when and how many times we generate symlinks for GOMA (cc @dnfield). The bottlenecks then become script executions in Dart. Specifically, Then there a are a couple scripts in Dart as well as engine that attempt to read Git revisions and such for versioning. This can also be done once upfront and stashed away in a GN variable. Once these are tackled, I believe everything should complete in well under a second. |
It used to be that GN could not generate compile commands on its own. Instead, we would use Ninja to do the same in a separate invocation after GN. This worked but the invocation took about a second to complete. Now that GN can generate the compile commands as it is generating the Ninja build rules, we ask it generate the compile commands directly. The commands seem identical and IDE integrations continue to work. One difference now is that the compile commands are now generated in the build directory instead of the out directory like earlier. I think this is easier to reason about but if others think we need the old behavior, I can add a symlink to the compile_commands.json. This knocks 0.9 to 1 seconds off of a no-op build compared to numbers in flutter/flutter#81074. ``` $ time ./flutter/tools/gn --unopt Generating GN files in: out/host_debug_unopt Generating Xcode projects took 244ms Generating compile_commands took 104ms Done. Made 739 targets from 228 files in 1781ms ./flutter/tools/gn --unopt 3.07s user 3.04s system 325% cpu 1.875 total ``` Related to flutter/flutter#81074
`--trace-gn` to `./flutter/tools/gn` should now dump a `gn_trace.json` in the build directory. This is not on by default because capturing and generating the traces seems to take about a second itself. So it is opt-in. Related to flutter/flutter#81074
cc @aam @rmacnak-google: Is there a way we can reduce the usage of script files in GN? |
I expect all the list_dart_files.py can be removed; I believe it predates the ability of our tools to generate depfiles. |
TEST=ci Bug: flutter/flutter#81074 Change-Id: I6e06e21d358fd4aafd37960803269796d2e62753 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196983 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
…apshots. GN/Ninja will discover them via the depfile created alongside the snapshot. Bug: flutter/flutter#81074 Change-Id: I6e0f07214e8ea29e6d23261c71558da06fd2223a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196982 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
xref https://dart-review.googlesource.com/c/sdk/+/196981. Thanks! I'll stash the iOS and Mac SDK details in a GN variable. I already patched compile_commands.json generation so its now not a separate step (saves 1 second). With the three fixes, I think we should be well under two seconds. I'll see if we can get rid of engine versioning from Git SHAs. We never exposed that to users so I don't think its absolutely necessary (we do use it to version caches). |
We do have a test in the framework that verifies Lines 137 to 146 in b8833af
This helps protect against issues where a bug in a builder causes it to upload the wrong git hash to a particular bucket, e.g. it thinks it's building head but it's not |
…ation snapshots." This reverts commit a23c31b. Reason for revert: The bootstrapping compilations are a bit confused about whose deps they're writing Original change's description: > [build] Don't list Dart sources up front when creating application snapshots. > > GN/Ninja will discover them via the depfile created alongside the snapshot. > > Bug: flutter/flutter#81074 > Change-Id: I6e0f07214e8ea29e6d23261c71558da06fd2223a > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196982 > Reviewed-by: Ben Konyi <bkonyi@google.com> > Commit-Queue: Ryan Macnak <rmacnak@google.com> TBR=bkonyi@google.com,rmacnak@google.com,chinmaygarde@google.com Change-Id: I267b6bac2676a18f57291c8472fab5c2aaa60284 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: flutter/flutter#81074 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197000 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
…cation snapshots." Fix `application_snapshot`'s depfile to track the sources of the application instead of the compiler. Split compiling the compiler into a separate GN target with its own depfile. Bug: flutter/flutter#81074 Change-Id: I0fb23ada40a6241ee3dde7f6cfebdd121b9a4224 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/197020 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
…ecuting scripts at GN time. Bug: flutter/flutter#81074 Change-Id: I3fba7743f89b970dfd8d4d47b21f7d51be7a9cdb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196981 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Chinmay Garde <chinmaygarde@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
dart-lang/sdk@8d436a2 is causing unnecessary operations to run in no-op engine builds. If I run:
the second run of Can you revert dart-lang/sdk@8d436a2? Regarding the broader issue highlighted in this bug: in my workflow I typically only need to run @chinmaygarde what scenarios require frequently rerunning |
@jason-simmons Can you run |
…ys re-executing scripts at GN time." This reverts commit 8d436a2. Reason for revert: ninja is always dirty Original change's description: > [build] Track glob dependencies via depfiles, instead of always re-executing scripts at GN time. > > Bug: flutter/flutter#81074 > Change-Id: I3fba7743f89b970dfd8d4d47b21f7d51be7a9cdb > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196981 > Commit-Queue: Ryan Macnak <rmacnak@google.com> > Reviewed-by: Chinmay Garde <chinmaygarde@google.com> > Reviewed-by: Ben Konyi <bkonyi@google.com> # Not skipping CQ checks because original CL landed > 1 day ago. Bug: flutter/flutter#81074 Change-Id: I74c9ce055ad49107ae0d21f2f3b9b74991fc81d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198441 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
Based on the @rmacnak-google I can get this to work as expected in the Flutter engine build by changing dart-lang/sdk@8d436a2#diff-40dd701de08faf64c714b08263634be72ff06ced2cbb199e67c5ec4f516c2d9eR32 |
@jason-simmons I believe @rmacnak-google is OoO today, so if you have something working locally, sending out a CL for it is probably the fastest thing. |
The depfile script was reverted in the Dart SDK: dart-lang/sdk@5c0ff97 |
…ays re-executing scripts at GN time." Use a relative path for the depfile's target to match Ninja's expectation; otherwise it thinks the target is always dirty. TEST=build twice Bug: flutter/flutter#81074 Change-Id: I4cae7ab55f79b5206521c7090502c0769d2b5277 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198443 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
This based on an observation that no-op engine builds during development were getting steadily slower over time.
Usually, even for no-op builds, Engine developers run
gn gen
(invoked by./flutter/tools/gn
) followed by theninja
invocation to generate build artifacts. Just runningninja
is sufficient to pick up changes to GN rules themselves but this does not pick up changes to GN args. So, most just run the two invocations in order. This workflow has been getting alarmingly slow over time.On my eng Macbook Pro,
gn gen
takes ~4s today. It used to take less than 300ms earlier (say 3 years ago).Just running
ninja
on the other hand seems to take 300ms which seems fine to me.Taking >4s for a no-op builds breaks flow. I used to be able to build on save and I can't do that anymore. Also, given the trend, this is probably going to get worse without some effort to arrest the increase. I can't tell how much of the increase is from additional targets, additional use of scripts in GN, or, just the effects of running GN on my laptop in the WFH environment vs. using the beasts in the office.
GN and Ninja have built in tools to profile the various steps and we should track what the most expensive steps are. Typically, the guidance has been to avoid Python or Dart scripts referenced in GN rules as they are typically the bottleneck. To avoid having these scripts, newer versions of GN have built-in functions that we could probably use. I am positive there are tons of low hanging fruit that will significantly improve productivity of engine developers. Separately, we don't have (or adhere to) documented best practices for authoring GN rules. Perhaps now is the time to set that up. Also, perhaps there is a way to benchmark how long no-op builds take so we can figure out trends.
The text was updated successfully, but these errors were encountered: