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

Unified Diff: runtime/bin/vmservice_impl.cc

Issue 533073005: Reduce service isolate startup time from ~80ms to ~30ms (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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
Index: runtime/bin/vmservice_impl.cc
diff --git a/runtime/bin/vmservice_impl.cc b/runtime/bin/vmservice_impl.cc
index 4debf74b0790f1ce4043ee1bd5fc807455fa0a37..6eacdf64a8cfd8205aea38e995cc9ef47d8fe74a 100644
--- a/runtime/bin/vmservice_impl.cc
+++ b/runtime/bin/vmservice_impl.cc
@@ -86,6 +86,48 @@ class Resources {
DISALLOW_IMPLICIT_CONSTRUCTORS(Resources);
};
+
+void TriggerResourceLoad(Dart_NativeArguments args) {
+ Dart_Handle library = Dart_RootLibrary();
+ ASSERT(!Dart_IsError(library));
+ Dart_Handle result = VmService::LoadResources(library);
+ ASSERT(!Dart_IsError(result));
+}
+
+
+struct VmServiceIONativeEntry {
+ const char* name;
+ int num_arguments;
+ Dart_NativeFunction function;
+};
+
+
+static VmServiceIONativeEntry _VmServiceIONativeEntries[] = {
+ {"VMServiceIO_TriggerResourceLoad", 0, TriggerResourceLoad},
siva 2014/09/09 00:40:58 in resources.dart triggerResourceLoad is not decla
+};
+
+
+static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name,
+ int num_arguments,
+ bool* auto_setup_scope) {
+ const char* function_name = NULL;
+ Dart_Handle result = Dart_StringToCString(name, &function_name);
+ ASSERT(!Dart_IsError(result));
+ ASSERT(function_name != NULL);
+ *auto_setup_scope = true;
+ intptr_t n =
+ sizeof(_VmServiceIONativeEntries) / sizeof(_VmServiceIONativeEntries[0]);
+ for (intptr_t i = 0; i < n; i++) {
+ VmServiceIONativeEntry entry = _VmServiceIONativeEntries[i];
+ if ((strcmp(function_name, entry.name) == 0) &&
+ (num_arguments == entry.num_arguments)) {
+ return entry.function;
+ }
+ }
+ return NULL;
+}
+
+
const char* VmService::error_msg_ = NULL;
bool VmService::Start(const char *server_ip, intptr_t server_port) {
@@ -103,7 +145,7 @@ bool VmService::_Start(const char *server_ip, intptr_t server_port) {
ASSERT(Dart_CurrentIsolate() == NULL);
Dart_Isolate isolate = Dart_GetServiceIsolate(NULL);
if (isolate == NULL) {
- error_msg_ = "Internal error.";
+ error_msg_ = "Dart_GetServiceIsolate failed.";
return false;
}
Dart_EnterIsolate(isolate);
@@ -111,12 +153,15 @@ bool VmService::_Start(const char *server_ip, intptr_t server_port) {
// Install our own library tag handler.
Dart_SetLibraryTagHandler(LibraryTagHandler);
Dart_Handle result;
- Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName);
- // Expect a library.
- ASSERT(library != Dart_Null());
- SHUTDOWN_ON_ERROR(library);
- result = Dart_FinalizeLoading(false);
- ASSERT(!Dart_IsError(result));
+ Dart_Handle library;
+ {
+ library = LoadScript(kVMServiceIOLibraryScriptResourceName);
+ // Expect a library.
+ ASSERT(library != Dart_Null());
+ SHUTDOWN_ON_ERROR(library);
+ result = Dart_FinalizeLoading(false);
+ ASSERT(!Dart_IsError(result));
+ }
siva 2014/09/09 00:40:58 Why is this is a special scope?
Cutch 2014/09/10 15:11:23 I was using scoped timers. Removing extra scopes.
Dart_ExitScope();
Dart_ExitIsolate();
bool retval = Dart_IsolateMakeRunnable(isolate);
@@ -127,39 +172,50 @@ bool VmService::_Start(const char *server_ip, intptr_t server_port) {
return false;
}
- Dart_EnterIsolate(isolate);
- Dart_EnterScope();
- library = Dart_RootLibrary();
- // Set requested TCP port.
- DartUtils::SetStringField(library, "_ip", server_ip);
- // If we have a port specified, start the server immediately.
- bool auto_start = server_port >= 0;
- if (server_port < 0) {
- // Adjust server_port to port 0 which will result in the first available
- // port when the HTTP server is started.
- server_port = 0;
+ {
+ Dart_EnterIsolate(isolate);
+ Dart_EnterScope();
+ library = Dart_RootLibrary();
+ result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL);
+ ASSERT(!Dart_IsError(result));
+ // Set requested TCP port.
+ DartUtils::SetStringField(library, "_ip", server_ip);
+ // If we have a port specified, start the server immediately.
+ bool auto_start = server_port >= 0;
+ if (server_port < 0) {
+ // Adjust server_port to port 0 which will result in the first available
+ // port when the HTTP server is started.
+ server_port = 0;
+ }
+ // Set initial state.
+ DartUtils::SetIntegerField(library, "_port", server_port);
+ Dart_SetField(library,
+ DartUtils::NewString("_autoStart"),
+ Dart_NewBoolean(auto_start));
+ // We cannot register for signals on windows.
+ #if defined(TARGET_OS_WINDOWS)
+ const bool is_windows = true;
+ #else
+ const bool is_windows = false;
+ #endif
+ Dart_SetField(library,
+ DartUtils::NewString("_isWindows"),
+ Dart_NewBoolean(is_windows));
siva 2014/09/09 00:40:58 Can write this: #if defined(TARGET_OS_WINDOWS) Dar
Cutch 2014/09/10 15:11:23 Done.
+ }
+
+
+ {
+ // Get _getWatchSignalInternal from dart:io.
+ Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io");
siva 2014/09/09 00:40:58 use DartUtils::kIOLibURL instead of "dart:io"
Cutch 2014/09/10 15:11:23 Done.
+ Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str);
+ Dart_Handle function_name =
+ Dart_NewStringFromCString("_getWatchSignalInternal");
+ Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL);
+ // Invoke main.
+ result =
+ Dart_Invoke(library, DartUtils::NewString("main"), 1, &signal_watch);
+ SHUTDOWN_ON_ERROR(result);
}
siva 2014/09/09 00:40:58 Ditto question about why these two blocks are setu
Cutch 2014/09/10 15:11:23 Done here and elsewhere.
- // Set initial state.
- DartUtils::SetIntegerField(library, "_port", server_port);
- Dart_SetField(library,
- DartUtils::NewString("_autoStart"),
- Dart_NewBoolean(auto_start));
- // We cannot register for signals on windows.
-#if defined(TARGET_OS_WINDOWS)
- const bool is_windows = true;
-#else
- const bool is_windows = false;
-#endif
- Dart_SetField(library,
- DartUtils::NewString("_isWindows"),
- Dart_NewBoolean(is_windows));
-
- // Invoke main.
- result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
- SHUTDOWN_ON_ERROR(result);
- // Load resources.
- result = LoadResources(library);
- SHUTDOWN_ON_ERROR(result);
Dart_ExitScope();
Dart_ExitIsolate();
« no previous file with comments | « runtime/bin/vmservice_impl.h ('k') | runtime/vm/service.h » ('j') | runtime/vm/service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698