Double speed of Parcel.writeString().
Previous logic was using GetStringUTFChars() and GetStringCritical(), which resulted in making a new temporary heap allocation and an extra memcpy(). The new approach in this CL bypasses those operations by asking the JNI helpers to copy directly into the Parcel buffer. This does mean that the contract for writing strings (prefixed with length) is now duplicated in Parcel.cpp and android_os_Parcel.cpp, so we leave docs to ensure future maintainers keep them in sync. Benchmarking shows that this change improves performance by ~36% for UTF-8 strings and ~52% for UTF-16 strings: Before: timeWriteString8[simple]_mean: 1323 timeWriteString8[complex]_mean: 2103 timeWriteString16[simple]_mean: 1427 timeWriteString16[complex]_mean: 1368 After: timeWriteString8[simple]_mean: 846 timeWriteString8[complex]_mean: 1671 timeWriteString16[simple]_mean: 685 timeWriteString16[complex]_mean: 748 Bug: 172562452 Test: atest CorePerfTests:android.os.ParcelStringPerfTest Exempt-From-Owner-Approval: trivial docs Change-Id: I57754eac7af235a0a1bce9642d4923856bb04b78
Loading
Please register or sign in to comment