@@ -99,34 +99,38 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9999 // operating system loading the executable and its libraries.
100100 const long long runner_entry_ms = MillisecondsSinceProcessStart ();
101101
102- // Renderer choice, measured rather than assumed.
102+ // Renderer choice. Read MARKTEXT_IMPELLER here; applied to the project
103+ // below, because only the project can carry it.
103104 //
104- // The trace narrowed a two-second launch down to `window.Create()`, which is
105- // where the engine comes up, the snapshot is read and the graphics surface is
106- // made. Impeller became the default Windows renderer after version 1.2.3 was
107- // built, so it was the obvious suspect and this switch existed to turn it
108- // off.
105+ // The first attempt at this set FLUTTER_ENGINE_SWITCHES and
106+ // FLUTTER_ENGINE_SWITCH_1=enable-impeller=false. That does nothing in a
107+ // release build: GetSwitchesFromEnvironment in the engine is wrapped in
108+ // `#ifndef FLUTTER_RELEASE` and returns an empty list, so every shipped
109+ // build ran Impeller no matter what the variable said — and the trace line
110+ // reported the request rather than the result, which made an A/B of two
111+ // identical runs look like an answer. set_impeller_switch is the supported
112+ // way and is read directly by FlutterWindowsEngine.
109113 //
110- // Four launches of one binary settled it: with Impeller the view took 2154
111- // and 2130 ms, without it 2411 and 2511 ms. Turning it off is 320 ms slower,
112- // and the Dart side that follows slowed with it. Impeller is not the cost,
113- // and forcing it off was a regression — so the default is now to leave the
114- // engine alone .
114+ // Off by default on Windows, because Impeller is what the launch cost is:
115+ // 3.44.9, which has no Impeller on Windows at all, creates the view in 284
116+ // and 306 ms; 3.47.2 with Impeller takes 2130 to 3330 ms on the same
117+ // machine and the same source. flutter/flutter#191860 measures the same
118+ // thing on a minimal project — 54 ms on Skia against 1183 ms on Impeller .
115119 //
116- // The switch stays, inverted, because the next renderer question will want
117- // it: MARKTEXT_IMPELLER=0 disables Impeller for one launch. The engine reads
118- // its switches from the environment — FLUTTER_ENGINE_SWITCHES holds the
119- // count, FLUTTER_ENGINE_SWITCH_<n> the switches — and an engine that no
120- // longer understands this one ignores it.
120+ // The default is baked in at build time (MARKTEXT_IMPELLER_DEFAULT, set by
121+ // CI) so that two installers can be compared without anyone having to set
122+ // anything: a variable left over from an earlier experiment has already
123+ // made one set of measurements say the opposite of what was intended.
124+ // MARKTEXT_IMPELLER=1/0 still overrides it for a single launch.
125+ #ifndef MARKTEXT_IMPELLER_DEFAULT
126+ #define MARKTEXT_IMPELLER_DEFAULT 0
127+ #endif
128+ bool enable_impeller = MARKTEXT_IMPELLER_DEFAULT != 0 ;
121129 wchar_t impeller_choice[8 ] = {0 };
122130 const DWORD impeller_len = ::GetEnvironmentVariableW (
123131 L" MARKTEXT_IMPELLER" , impeller_choice, 8 );
124- const bool disable_impeller =
125- impeller_len > 0 && impeller_len < 8 && impeller_choice[0 ] == L' 0' ;
126- if (disable_impeller) {
127- ::SetEnvironmentVariableW (L" FLUTTER_ENGINE_SWITCHES" , L" 1" );
128- ::SetEnvironmentVariableW (L" FLUTTER_ENGINE_SWITCH_1" ,
129- L" enable-impeller=false" );
132+ if (impeller_len > 0 && impeller_len < 8 ) {
133+ enable_impeller = impeller_choice[0 ] == L' 1' ;
130134 }
131135 // Attach to console when present (e.g., 'flutter run') or create a
132136 // new console when running with a debugger.
@@ -139,6 +143,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
139143 ::CoInitializeEx (nullptr , COINIT_APARTMENTTHREADED );
140144
141145 flutter::DartProject project (L" data" );
146+ project.set_impeller_switch (enable_impeller
147+ ? flutter::ImpellerSwitch::Enabled
148+ : flutter::ImpellerSwitch::Disabled);
142149
143150 std::vector<std::string> command_line_arguments =
144151 GetCommandLineArguments ();
@@ -148,8 +155,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
148155 command_line_arguments.push_back (FormatTraceArgument (
149156 " --mt-trace-engine-start=" , MillisecondsSinceProcessStart ()));
150157 // So the trace says which renderer the run was asked for.
151- command_line_arguments.push_back (disable_impeller ? " --mt-trace-impeller=0 "
152- : " --mt-trace-impeller=1 " );
158+ command_line_arguments.push_back (enable_impeller ? " --mt-trace-impeller=1 "
159+ : " --mt-trace-impeller=0 " );
153160
154161 project.set_dart_entrypoint_arguments (std::move (command_line_arguments));
155162
0 commit comments