Skip to content

Commit 4551003

Browse files
srawlinsCommit Queue
authored andcommitted
http profiling: Remove unnecessary async from function
This makes the code simpler, and more readable, and is a no-op. `_createHttpProfileRequestFromProfileMap` was being always awaited, but the function did not need to return a Future. So we make it synchronous, remove the awaits. That then allows `_getHttpProfileRequest` to not be asynchronous as well. Change-Id: I1c9854e122e9093e2305f71cc311045f17e81ae9 CoreLibraryReviewExempt: no API; just profiling impl code Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416260 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent b03e7c7 commit 4551003

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

sdk/lib/io/network_profiling.dart

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const int _versionMinor = 0;
1111
const String _tcpSocket = 'tcp';
1212
const String _udpSocket = 'udp';
1313

14-
// Creates a Map conforming to the HttpProfileRequest type defined in the
15-
// dart:io service extension spec from an element of dart:developer's
16-
// [_developerProfilingData].
17-
Future<Map<String, dynamic>> _createHttpProfileRequestFromProfileMap(
14+
/// Creates a Map conforming to the `HttpProfileRequest` type defined in the
15+
/// dart:io service extension spec from an element of dart:developer's
16+
/// `_developerProfilingData`.
17+
Map<String, Object?> _createHttpProfileRequestFromProfileMap(
1818
Map<String, dynamic> requestProfile, {
1919
required bool ref,
20-
}) async {
20+
}) {
2121
final responseData = requestProfile['responseData'] as Map<String, dynamic>;
2222

23-
return <String, dynamic>{
23+
return {
2424
'type': '${ref ? '@' : ''}HttpProfileRequest',
2525
'id': requestProfile['id']!,
2626
'isolateId': requestProfile['isolateId']!,
@@ -70,6 +70,9 @@ abstract class _NetworkProfiling {
7070
registerExtension(_kClearHttpProfileRPC, _serviceExtensionHandler);
7171
}
7272

73+
// Note this function only returns a `Future` because that is required by the
74+
// signature of `registerExtension`. We might be able to change the signature
75+
// of ServiceExtensionHandler to use `FutureOr` instead of `Future`.
7376
static Future<ServiceExtensionResponse> _serviceExtensionHandler(
7477
String method,
7578
Map<String, String> parameters,
@@ -93,23 +96,21 @@ abstract class _NetworkProfiling {
9396
'timestamp': DateTime.now().microsecondsSinceEpoch,
9497
'requests': [
9598
...HttpProfiler.serializeHttpProfileRequests(updatedSince),
96-
...await Future.wait(
97-
getHttpClientProfilingData()
98-
.where(
99-
(final Map<String, dynamic> p) =>
100-
updatedSince == null ||
101-
(p['_lastUpdateTime'] as int) >= updatedSince,
102-
)
103-
.map(
104-
(p) =>
105-
_createHttpProfileRequestFromProfileMap(p, ref: true),
106-
),
107-
),
99+
...getHttpClientProfilingData()
100+
.where(
101+
(final Map<String, dynamic> p) =>
102+
updatedSince == null ||
103+
(p['_lastUpdateTime'] as int) >= updatedSince,
104+
)
105+
.map(
106+
(p) =>
107+
_createHttpProfileRequestFromProfileMap(p, ref: true),
108+
),
108109
],
109110
});
110111
break;
111112
case _kGetHttpProfileRequestRPC:
112-
responseJson = await _getHttpProfileRequest(parameters);
113+
responseJson = _getHttpProfileRequest(parameters);
113114
break;
114115
case _kClearHttpProfileRPC:
115116
HttpProfiler.clear();
@@ -174,23 +175,20 @@ String _setHttpEnableTimelineLogging(Map<String, String> parameters) {
174175
return _success();
175176
}
176177

177-
Future<String> _getHttpProfileRequest(Map<String, String> parameters) async {
178-
if (!parameters.containsKey('id')) {
178+
String _getHttpProfileRequest(Map<String, String> parameters) {
179+
final id = parameters['id'];
180+
if (id == null) {
179181
throw _missingArgument('id');
180182
}
181-
final id = parameters['id']!;
182-
final request;
183+
final Map<String, Object?>? request;
183184
if (id.startsWith('from_package/')) {
184185
final profileMap = getHttpClientProfilingData().elementAtOrNull(
185186
int.parse(id.substring('from_package/'.length)) - 1,
186187
);
187188
request =
188189
profileMap == null
189190
? null
190-
: await _createHttpProfileRequestFromProfileMap(
191-
profileMap,
192-
ref: false,
193-
);
191+
: _createHttpProfileRequestFromProfileMap(profileMap, ref: false);
194192
} else {
195193
request = HttpProfiler.getHttpProfileRequest(id)?.toJson(ref: false);
196194
}

0 commit comments

Comments
 (0)