Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26909] Android: Improve V8 cold start performance

GitHub Issuen/a
TypeImprovement
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2019-04-12T14:21:26.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.1.0
ComponentsAndroid
Labelsandroid, performance, v8
ReporterJoshua Quick
AssigneeGary Mathews
Created2019-03-18T22:17:02.000+0000
Updated2020-01-23T20:09:33.000+0000

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](https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/v8/src/native/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, ¤tTime);
	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.

Comments

  1. Gary Mathews 2019-04-01

    master: https://github.com/appcelerator/titanium_mobile/pull/10817 v8_titanium: https://github.com/appcelerator/v8_titanium/pull/44
  2. Samir Mohammed 2019-05-30

    Closing ticket, improvement verified in SDK version 8.1.0.v20190529135224 performance updates are able to be seen when launching from a cold start. Test and other information can be found at: master: https://github.com/appcelerator/titanium_mobile/pull/10817 v8_titanium: https://github.com/appcelerator/v8_titanium/pull/44

JSON Source