Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Unified Diff: sdk/lib/developer/timeline.dart

Issue 1441683005: Fast path Dart Timeline events with no arguments to avoid calling JSON.encode (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/observatory/tests/service/get_vm_timeline_rpc_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/developer/timeline.dart
diff --git a/sdk/lib/developer/timeline.dart b/sdk/lib/developer/timeline.dart
index 55de99dbb92317ec1d63e830a1e35a11aa95f040..15ed062123e8953ced686f007263e261435fb91f 100644
--- a/sdk/lib/developer/timeline.dart
+++ b/sdk/lib/developer/timeline.dart
@@ -44,17 +44,14 @@ class Timeline {
'name',
'Must be a String');
}
- Map instantArguments = {
- 'isolateNumber': '${Timeline._isolateId}'
- };
+ Map instantArguments;
if (arguments is Map) {
- instantArguments.addAll(arguments);
+ instantArguments = new Map.from(arguments);
}
- String argumentsAsJson = JSON.encode(instantArguments);
_reportInstantEvent(_getTraceClock(),
'Dart',
name,
- argumentsAsJson);
+ _argumentsAsJson(instantArguments));
}
@@ -72,8 +69,8 @@ class Timeline {
}
static final List<_SyncBlock> _stack = new List<_SyncBlock>();
-
static final int _isolateId = _getIsolateNum();
+ static final String _isolateIdString = _isolateId.toString();
}
/// An asynchronous task on the timeline. An asynchronous task can have many
@@ -121,19 +118,16 @@ class TimelineTask {
'name',
'Must be a String');
}
- Map instantArguments = {
- 'isolateNumber': '${Timeline._isolateId}'
- };
+ Map instantArguments;
if (arguments is Map) {
- instantArguments.addAll(arguments);
+ instantArguments = new Map.from(arguments);
}
- String argumentsAsJson = JSON.encode(instantArguments);
_reportTaskEvent(_getTraceClock(),
_taskId,
'n',
'Dart',
name,
- argumentsAsJson);
+ _argumentsAsJson(instantArguments));
}
/// Finish the last synchronous operation that was started.
@@ -180,14 +174,12 @@ class _AsyncBlock {
// Emit the start event.
void _start() {
- arguments['isolateNumber'] = '${Timeline._isolateId}';
- String argumentsAsJson = JSON.encode(arguments);
_reportTaskEvent(_getTraceClock(),
_taskId,
'b',
category,
name,
- argumentsAsJson);
+ _argumentsAsJson(arguments));
}
// Emit the finish event.
@@ -197,7 +189,7 @@ class _AsyncBlock {
'e',
category,
name,
- JSON.encode({}));
+ _argumentsAsJson(null));
}
}
@@ -220,20 +212,27 @@ class _SyncBlock {
/// Finish this block of time. At this point, this block can no longer be
/// used.
void finish() {
- var end = _getTraceClock();
-
- arguments['isolateNumber'] = '${Timeline._isolateId}';
-
- // Encode arguments map as JSON before reporting.
- var argumentsAsJson = JSON.encode(arguments);
-
// Report event to runtime.
_reportCompleteEvent(_start,
- end,
+ _getTraceClock(),
category,
name,
- argumentsAsJson);
+ _argumentsAsJson(arguments));
+ }
+}
+
+String _fastPathArguments;
+String _argumentsAsJson(Map arguments) {
+ if ((arguments == null) || (arguments.length == 0)) {
+ // Fast path no arguments. Avoid calling JSON.encode.
+ if (_fastPathArguments == null) {
+ _fastPathArguments = '{"isolateNumber":"${Timeline._isolateId}"}';
+ }
+ return _fastPathArguments;
}
+ // Add isolateNumber to arguments map.
+ arguments['isolateNumber'] = Timeline._isolateIdString;
+ return JSON.encode(arguments);
}
/// Returns the next async task id.
@@ -264,4 +263,4 @@ external void _reportCompleteEvent(int start,
external void _reportInstantEvent(int start,
String category,
String name,
- String argumentsAsJson);
+ String argumentsAsJson);
« no previous file with comments | « runtime/observatory/tests/service/get_vm_timeline_rpc_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698