Skip to content

Commit 98d69bb

Browse files
author
Anna Gringauze
authored
Add an option to dwds to suppress emitting debug events (#1467)
* Add an option to dwds to suppress emitting debug events Flutter sends a stream of debug events to dwds for profiling information that can slow down debugging for apps that refresh frames frequently. Add an option to disable debug events as a workaround until we can improve performance of communication between the injected client and dwds. Workaround for: #1466 * Address CR comments
1 parent 64620de commit 98d69bb

File tree

6 files changed

+266
-214
lines changed

6 files changed

+266
-214
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
**Breaking changes:**
1010

1111
- Add `sdkDir` argument to `Dwds.start` to help file resolution for sdk uris.
12+
- Add `emitDebugEvents` argument to `Dwds.start` to suppress emitting debug
13+
events from the injected client.
1214

1315
## 11.5.1
1416

dwds/lib/dwds.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class Dwds {
113113
bool enableDevtoolsLaunch,
114114
DevtoolsLauncher devtoolsLauncher,
115115
Uri sdkDir,
116+
bool emitDebugEvents,
116117
}) async {
117118
hostname ??= 'localhost';
118119
enableDebugging ??= true;
@@ -123,6 +124,7 @@ class Dwds {
123124
enableDevtoolsLaunch ??= true;
124125
spawnDds ??= true;
125126
globalLoadStrategy = loadStrategy;
127+
emitDebugEvents ??= true;
126128

127129
await DartUri.initialize(sdkDir: sdkDir);
128130

@@ -162,6 +164,7 @@ class Dwds {
162164
useSseForInjectedClient: useSseForInjectedClient,
163165
extensionUri: extensionUri,
164166
enableDevtoolsLaunch: enableDevtoolsLaunch,
167+
emitDebugEvents: emitDebugEvents,
165168
);
166169

167170
var devHandler = DevHandler(

dwds/lib/src/handlers/injector.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ class DwdsInjector {
3838
final _logger = Logger('DwdsInjector');
3939
final bool _enableDevtoolsLaunch;
4040
final bool _useSseForInjectedClient;
41+
final bool _emitDebugEvents;
4142

4243
DwdsInjector(
4344
this._loadStrategy, {
4445
Future<String> extensionUri,
4546
bool enableDevtoolsLaunch,
4647
bool useSseForInjectedClient,
48+
bool emitDebugEvents,
4749
}) : _extensionUri = extensionUri,
4850
_enableDevtoolsLaunch = enableDevtoolsLaunch,
49-
_useSseForInjectedClient = useSseForInjectedClient ?? true;
51+
_useSseForInjectedClient = useSseForInjectedClient ?? true,
52+
_emitDebugEvents = emitDebugEvents ?? true;
5053

5154
/// Returns the embedded dev handler paths.
5255
///
@@ -107,6 +110,7 @@ class DwdsInjector {
107110
await _extensionUri,
108111
_loadStrategy,
109112
_enableDevtoolsLaunch,
113+
_emitDebugEvents,
110114
);
111115
body += await _loadStrategy.bootstrapFor(entrypoint);
112116
_logger.info('Injected debugging metadata for '
@@ -137,6 +141,7 @@ String _injectClientAndHoistMain(
137141
String extensionUri,
138142
LoadStrategy loadStrategy,
139143
bool enableDevtoolsLaunch,
144+
bool emitDebugEvents,
140145
) {
141146
var bodyLines = body.split('\n');
142147
var extensionIndex =
@@ -156,6 +161,7 @@ String _injectClientAndHoistMain(
156161
extensionUri,
157162
loadStrategy,
158163
enableDevtoolsLaunch,
164+
emitDebugEvents,
159165
);
160166
result += '''
161167
// Injected by dwds for debugging support.
@@ -189,6 +195,7 @@ String _injectedClientSnippet(
189195
String extensionUri,
190196
LoadStrategy loadStrategy,
191197
bool enableDevtoolsLaunch,
198+
bool emitDebugEvents,
192199
) {
193200
var injectedBody = 'window.\$dartAppId = "$appId";\n'
194201
'window.\$dartReloadConfiguration = "${loadStrategy.reloadConfiguration}";\n'
@@ -198,6 +205,7 @@ String _injectedClientSnippet(
198205
'window.\$dwdsDevHandlerPath = "$devHandlerPath";\n'
199206
'window.\$dwdsEnableDevtoolsLaunch = $enableDevtoolsLaunch;\n'
200207
'window.\$dartEntrypointPath = "$entrypointPath";\n'
208+
'window.\$dartEmitDebugEvents = "$emitDebugEvents";\n'
201209
'${loadStrategy.loadClientSnippet(_clientScript)}';
202210
if (extensionUri != null) {
203211
injectedBody += 'window.\$dartExtensionUri = "$extensionUri";\n';

0 commit comments

Comments
 (0)