Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26909

Android: Improve V8 cold start performance

    Details

      Description

      Summary:
      During an app cold start, Titanium will create a V8 Isolate one time for the lifetime of the app to be used as the JavaScript runtime. The C++ function call v8::Isolate::New() is unusually slow.
      V8Runtime.cpp#L228

      By running adding the following code, I'm able to benchmark this function call.

      #include <time.h>
      uint64_t GetCurrentTimeInMilliseconds()
      {
      	struct timespec currentTime;
      	clock_gettime(CLOCK_MONOTONIC, &currentTime);
      	uint64_t value = (uint64_t)currentTime.tv_sec * (uint64_t)1000000;
      	value += (uint64_t)currentTime.tv_nsec / (uint64_t)1000;
      	return value / (uint64_t)1000;
      }
       
      JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeInit(...)
      {
      	// ...
      	uint64_t currentTime = GetCurrentTimeInMilliseconds();
      	isolate = Isolate::New(create_params);
      	LOGI(TAG, "### Isolate::New() duration: %d", (int)(GetCurrentTimeInMilliseconds() - currentTime));
      	// ...
      }
      

      The below are benchmarks from real physical devices:

      • Pixel 2 (Android 9.0; ARM64): 750ms
      • Nexus 4 (Android 4.4; ARM32): 2500ms

      The above eats about half the startup time on a simple "Hello World" project. It's unusually slow.

      To be investigated:

      • Supposedly, creating the Isolate with an empty snapshot created at build time should significantly improve the performance.
      • We should double check that the v8 .a static library was not compiled in debug mode.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gmathews Gary Mathews
                Reporter:
                jquick Joshua Quick
                Tester:
                Samir Mohammed
              • Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code