bytedeco/javacpp

Struct memory allocation is slow

Open

#299 aperta il 13 mag 2019

Vedi su GitHub
 (9 commenti) (0 reazioni) (0 assegnatari)Java (620 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (4279 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

I run a simple benchmark calling window API's GetSystemTime using JavaCpp's built-in windows API wrappers. This code allocates a struct, calls the native API and fetches some field from the struct:

		SYSTEMTIME systemtime = new SYSTEMTIME();
		windows.GetSystemTime(systemtime);
		return systemtime.wSecond();

Profiling shows that the first line takes >90% of the overall execution time

image

I believe that there is some space for optimization here. The same thing implemented with Bridj or JNR outperforms JNI+JavaCpp just because of faster allocation, see the benchmark at https://github.com/zakgof/java-native-benchmark.

Say, with Bridj allocation takes <50% of the overall time:

image

Guida contributor