aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-05-21 12:58:59 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-21 13:00:32 -0700
commit88f0f85fe775db0aac223050d1454c99e3f9f80e (patch)
treea2fef9444b95f3107afd085487cf08a673b0a284 /src/test/java/com/google/devtools/build/lib
parentcaed1a27756d513d437143186771981b5fcfcdcc (diff)
When using JDK9, replace naive StringCodec with an optimized codec that uses the String's underlying raw bytes. This avoids byte copying and UTF interpretation. Experiments show it is approximately 15(!) times faster than the naive StringCodec for serialization and 2 times faster for deserialization (10 times faster for non-ASCII strings).
PiperOrigin-RevId: 197441758
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/serialization/strings/StringCodecTest.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/strings/StringCodecTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/strings/StringCodecTest.java
index 178071c345..cd7ce33d54 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/serialization/strings/StringCodecTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/serialization/strings/StringCodecTest.java
@@ -14,17 +14,41 @@
package com.google.devtools.build.lib.skyframe.serialization.strings;
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodecRegistry;
+import com.google.devtools.build.lib.skyframe.serialization.UnsafeJdk9StringCodec;
import com.google.devtools.build.lib.skyframe.serialization.testutils.SerializationTester;
+import com.google.devtools.build.lib.skyframe.serialization.testutils.TestUtils;
+import com.google.protobuf.ByteString;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Basic tests for {@link StringCodec}. */
+/** Basic tests for {@link StringCodec} or {@link UnsafeJdk9StringCodec}. */
@RunWith(JUnit4.class)
public class StringCodecTest {
@Test
public void testCodec() throws Exception {
- new SerializationTester("usually precomputed and supports weird unicodes: (╯°□°)╯︵┻━┻ ")
+ new SerializationTester("usually precomputed and supports weird unicodes: (╯°□°)╯︵┻━┻ ", "")
.runTests();
}
+
+ @Test
+ public void sizeOk() throws Exception {
+ for (String str :
+ ImmutableList.of(
+ "//a/b/c/d/e/f/g/h/ijklmn:opqrstuvw.xyz",
+ "java/com/google/devtools/build/lib/util/more/strings",
+ "java/com/google/devtools/build/lib/util/more/strings/náme_with_àccent")) {
+ ByteString withSimple =
+ TestUtils.toBytesMemoized(
+ str, new ObjectCodecRegistry.Builder().add(StringCodecs.simple()).build());
+ ByteString withUnsafe =
+ TestUtils.toBytesMemoized(
+ str, new ObjectCodecRegistry.Builder().add(StringCodecs.asciiOptimized()).build());
+ assertWithMessage(str + " too big").that(withUnsafe.size()).isAtMost(withSimple.size());
+ }
+ }
}