Skip to content

Commit 7f94822

Browse files
znhuclaude
andcommitted
fix: Impeller 开关一直是空操作;改用 set_impeller_switch,CI 出双渲染器包
engine_switches.cc 里读 FLUTTER_ENGINE_SWITCHES 的整段被 #ifndef FLUTTER_RELEASE 包着,release 构建返回空列表。我们的包全是 --release,所以那条禁用 Impeller 的路从来没生效过,每个发出去的包跑的都是默认 Impeller;而日志那行报的是 "请求了什么"不是"实际用了什么"。 因此作废上一轮两条结论:"Impeller 不是原因"和"关掉慢 320ms"——那次 A/B 的 两个臂是同一个配置,差值是噪声。 修正后的图景自洽:3.44.9 的 Windows 根本没有 Impeller(dart_project.h 里连 ImpellerSwitch 都没有),284/306ms;3.47.2 默认 Impeller,2130~3330ms; flutter/flutter#191860 在最小工程上测得 Skia 54ms 对 Impeller 1183ms。 Windows 上的启动开销就是 Impeller,最初的假设是对的。 改用 project.set_impeller_switch(FlutterWindowsEngine 真正读的入口),默认值 由 CMake 在构建时烘进二进制,不再依赖运行机器上的变量——上一轮正是机器上残留 的 MARKTEXT_IMPELLER=0 让日志显示 off 而实际是 on。SDK 解除固定回到 3.47.2, 换渲染器而不是换 SDK;CI 每次产出 impeller-on / impeller-off 两个安装包。 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CsQpnQYnBNCShzcQro5TYe
1 parent 60a2fe8 commit 7f94822

4 files changed

Lines changed: 132 additions & 43 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
env:
15-
# Held at 3.44.9 on purpose, and not to be raised without measuring.
15+
# Back on a current SDK, with the renderer switched instead of the SDK.
1616
#
17-
# One source tree (f34574fa) was built on both SDKs and both installers run
18-
# on the machine that reported a slow start. Creating the engine view took
19-
# 306 and 284 ms on 3.44.9, and 3330 and 3137 ms on 3.47.2 — the same code,
20-
# the same machine, the same renderer setting, ten times the cost. That one
21-
# span is the whole of the two-to-four second launch that was chased for
22-
# days; everything this program does itself adds up to about 150 ms.
17+
# 3.44.9 was pinned because it launched ten times faster; the reason turned
18+
# out to be that 3.44.9 has no Impeller on Windows at all. The switch meant
19+
# to test that on 3.47 was a no-op: it set FLUTTER_ENGINE_SWITCHES, which
20+
# the engine reads only outside release builds, so both arms of the A/B ran
21+
# Impeller and the difference between them was noise.
2322
#
24-
# An exact version, not "stable": the comment here once said "pinned" while
25-
# the value said `stable`, which pins nothing, and two traces from different
26-
# weeks were compared as though only the source had changed.
27-
#
28-
# Before raising it: build both, launch both twice, read `creating the view`.
29-
# docs/v1.4.0/启动耗时排查.md has the numbers and how they were taken.
30-
FLUTTER_VERSION: 3.44.9
23+
# windows/runner now asks through set_impeller_switch, which is read. Two
24+
# installers come out of every build — one each way — until the numbers say
25+
# which the default should be. flutter/flutter#191860 measures the same
26+
# thing on a minimal project: 54 ms on Skia against 1183 ms on Impeller.
27+
FLUTTER_VERSION: 3.47.2
3128

3229
jobs:
3330
analyze:
@@ -100,9 +97,18 @@ jobs:
10097
retention-days: 14
10198

10299
build-windows:
103-
name: Build Windows
100+
name: Build Windows (Impeller ${{ matrix.impeller.label }})
104101
runs-on: windows-latest
105102
needs: analyze
103+
strategy:
104+
fail-fast: false
105+
matrix:
106+
# Baked in at build time rather than set on the machine under test: a
107+
# variable left from an earlier experiment already made one set of
108+
# measurements report the opposite of what was intended.
109+
impeller:
110+
- {label: 'off', value: '0'}
111+
- {label: 'on', value: '1'}
106112
steps:
107113
- uses: actions/checkout@v4
108114

@@ -137,6 +143,7 @@ jobs:
137143
# DLLs, 50 ms of runner prologue, and 2.7 seconds booting the engine
138144
# and loading app.so. app.so is 13.6 MB, and this is the one way to
139145
# make it smaller that costs no feature.
146+
$env:MARKTEXT_IMPELLER_DEFAULT = '${{ matrix.impeller.value }}'
140147
flutter build windows --release `
141148
--build-number=$env:GITHUB_RUN_NUMBER `
142149
--split-debug-info=build\symbols `
@@ -181,7 +188,7 @@ jobs:
181188
DefaultDirName={autopf}\MarkText Plus
182189
DefaultGroupName=MarkText Plus
183190
OutputDir=${{ github.workspace }}
184-
OutputBaseFilename=marktext-plus-setup-flutter-${{ env.FLUTTER_VERSION }}
191+
OutputBaseFilename=marktext-plus-setup-impeller-${{ matrix.impeller.label }}
185192
Compression=lzma2
186193
SolidCompression=yes
187194
SetupIconFile=${{ github.workspace }}\code\windows\runner\resources\app_icon.ico
@@ -243,14 +250,14 @@ jobs:
243250

244251
- uses: actions/upload-artifact@v4
245252
with:
246-
name: windows-x64-setup-flutter-${{ env.FLUTTER_VERSION }}-${{ github.sha }}
247-
path: marktext-plus-setup-flutter-${{ env.FLUTTER_VERSION }}.exe
253+
name: windows-x64-setup-impeller-${{ matrix.impeller.label }}-${{ github.sha }}
254+
path: marktext-plus-setup-impeller-${{ matrix.impeller.label }}.exe
248255
retention-days: 14
249256

250257
# Uploaded unzipped: the action zips the directory itself, and a nested
251258
# archive would need unpacking twice before the exe could be run.
252259
- uses: actions/upload-artifact@v4
253260
with:
254-
name: windows-x64-flutter-${{ env.FLUTTER_VERSION }}-${{ github.sha }}
261+
name: windows-x64-impeller-${{ matrix.impeller.label }}-${{ github.sha }}
255262
path: code/build/windows/x64/runner/Release/
256263
retention-days: 14

‎code/windows/CMakeLists.txt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ project(marktext_plus LANGUAGES CXX)
66
# the on-disk name of your application.
77
set(BINARY_NAME "marktext_plus")
88

9+
# Which renderer the shipped binary asks for, baked in rather than left to a
10+
# variable on the machine that runs it: two installers built from one source
11+
# can then be compared without anyone having to set anything, and a leftover
12+
# variable cannot silently make a measurement say the opposite of what was
13+
# meant. 0 (Skia) is the default because Impeller is what the Windows launch
14+
# cost is — see windows/runner/main.cpp and flutter/flutter#191860.
15+
if(DEFINED ENV{MARKTEXT_IMPELLER_DEFAULT})
16+
add_compile_definitions(
17+
MARKTEXT_IMPELLER_DEFAULT=$ENV{MARKTEXT_IMPELLER_DEFAULT})
18+
endif()
19+
920
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
1021
# versions of CMake.
1122
cmake_policy(VERSION 3.14...3.25)

‎code/windows/runner/main.cpp‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎docs/v1.4.0/启动耗时排查.md‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,3 +674,67 @@ Windows 构建改成两个 SDK 的矩阵:`3.47.2` 与 `3.44.9`,同一份源
674674
十倍,不值得为此回去。
675675
- 固定到 3.44.9 后,CI 的 analyze 与测试也在 3.44.9 上跑。本机开发用的是
676676
3.47.1,若某处用了 3.44 没有的 API,会在 CI 暴露而不是本机。
677+
678+
---
679+
680+
## 2026-08-28 续:那个开关一直是空操作,前一轮的结论作废
681+
682+
`shell/platform/common/engine_switches.cc`:
683+
684+
```cpp
685+
std::vector<std::string> GetSwitchesFromEnvironment() {
686+
std::vector<std::string> switches;
687+
#ifndef FLUTTER_RELEASE // ← 这里
688+
const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES";
689+
...
690+
#endif // !FLUTTER_RELEASE
691+
return switches;
692+
}
693+
```
694+
695+
**release 构建里它返回空。** 我们的包全是 `flutter build windows --release`,
696+
所以 `FLUTTER_ENGINE_SWITCHES` + `enable-impeller=false` 这条路
697+
**从来没有生效过**,每一个发出去的包跑的都是默认的 Impeller。
698+
699+
而日志里那行 `renderer: Impeller off` 报的是**我们请求了什么**,不是实际用了
700+
什么——两次"不同"的运行其实是同一个配置,把噪声(2154/2130 对 2411/2511)
701+
当成了结论。
702+
703+
因此**作废前一轮的两条结论**:
704+
- ~~"Impeller 不是原因"~~ —— 那次 A/B 的两个臂是同一个配置。
705+
- ~~"关掉 Impeller 慢 320 ms"~~ —— 同上,是噪声。
706+
707+
### 修正后的完整图景
708+
709+
| | 渲染器(实际) | creating the view |
710+
|---|---|---|
711+
| 3.44.9 | Skia —— 该版本 Windows **根本没有 Impeller**(`dart_project.h` 里连 `ImpellerSwitch` 都没有) | **284 / 306 ms** |
712+
| 3.47.2 | Impeller(默认,开关空操作) | 2130 / 2154 / 2411 / 2511 / 3137 / 3330 ms |
713+
| flutter/flutter#191860(3.47.1,最小工程,第三方实测) | Skia 54 ms · Impeller 1183 ms | — |
714+
715+
三组数据自洽:**Windows 上的启动开销就是 Impeller**。最初的假设是对的,
716+
把它"推翻"的那次实验是无效的。
717+
718+
### 改法
719+
720+
- 改用 `project.set_impeller_switch(ImpellerSwitch::Enabled/Disabled)`,
721+
这是 `FlutterWindowsEngine` 真正读的入口(`flutter_windows_engine.cc`
722+
先看 `project_->impeller_switch()`,再看环境变量——而环境变量那条在 release
723+
里拿到的是空列表)。
724+
- 默认值**在构建时烘进二进制**(`MARKTEXT_IMPELLER_DEFAULT`,由 CMake 从环境
725+
变量读入),不再依赖运行机器上的变量:上一轮就是因为机器上残留了一个
726+
`MARKTEXT_IMPELLER=0`,让日志显示 off 而实际是 on。`MARKTEXT_IMPELLER=1/0`
727+
仍可覆盖单次启动。
728+
- SDK 解除固定,回到 **3.47.2**——换渲染器而不是换 SDK。
729+
- CI 每次产出**两个安装包**:`marktext-plus-setup-impeller-off.exe` 与
730+
`-impeller-on.exe`,同一份源码、同一个 SDK,只差渲染器。
731+
732+
### 待测
733+
734+
装一个测两次、卸载再装另一个测两次,看 `creating the view`。
735+
**测之前先清掉机器上残留的 `MARKTEXT_IMPELLER`**(`setx MARKTEXT_IMPELLER ""`
736+
后重开窗口),否则它会覆盖掉烘进去的默认值——日志那行会如实显示,可以核对。
737+
738+
结果出来后把数据补到 flutter/flutter#191860(该 issue 昨天刚开、仍开着、
739+
带最小复现工程),而不是另开一条重复的。我们的数字更极端,且多了"3.44.9
740+
无 Impeller 只要 284 ms"这个版本对照。

0 commit comments

Comments
 (0)