Skip to content

Commit

Permalink
Improve performance of parsing unknown fields in Java (#9371)
Browse files Browse the repository at this point in the history
Credit should go to @elharo for most of these Java changes--I am just
cherry-picking them from our internal codebase. The one thing I did
change was to give the UTF-8 validation tests their own Bazel test
target. This makes it possible to give the other tests a shorter
timeout, which is important for UnknownFieldSetPerformanceTest in
particular.
  • Loading branch information
acozzette committed Jan 5, 2022
1 parent 1fe07f9 commit 36a2fe6
Show file tree
Hide file tree
Showing 6 changed files with 506 additions and 218 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -491,6 +491,7 @@ java_EXTRA_DIST=
java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java \
java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java \
java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \
java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java \
java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \
java/core/src/test/java/com/google/protobuf/Utf8Test.java \
java/core/src/test/java/com/google/protobuf/Utf8Utils.java \
Expand Down
35 changes: 30 additions & 5 deletions java/core/BUILD
Expand Up @@ -222,6 +222,7 @@ test_suite(
"core_build_test",
"conformance_test",
"core_tests",
"utf8_tests",
],
)

Expand All @@ -241,12 +242,17 @@ conformance_test(

junit_tests(
name = "core_tests",
srcs = glob(["src/test/java/**/*.java"], exclude = [
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
]),
size = "small",
srcs = glob(
["src/test/java/**/*.java"],
exclude = [
"src/test/java/com/google/protobuf/DecodeUtf8Test.java",
"src/test/java/com/google/protobuf/IsValidUtf8Test.java",
"src/test/java/com/google/protobuf/TestUtil.java",
"src/test/java/com/google/protobuf/TestUtilLite.java",
],
),
data = ["//:testdata"],
size = "large",
deps = [
":core",
":generic_test_protos_java_proto",
Expand All @@ -260,6 +266,24 @@ junit_tests(
]
)

# The UTF-8 validation tests are much slower than the other tests, so they get
# their own test target with a longer timeout.
junit_tests(
name = "utf8_tests",
size = "large",
srcs = [
"src/test/java/com/google/protobuf/DecodeUtf8Test.java",
"src/test/java/com/google/protobuf/IsValidUtf8Test.java",
"src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java",
],
deps = [
":core",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
],
)

java_lite_proto_library(
name = "generic_test_protos_java_proto_lite",
visibility = [
Expand Down Expand Up @@ -342,6 +366,7 @@ LITE_TEST_EXCLUSIONS = [
"src/test/java/com/google/protobuf/TypeRegistryTest.java",
"src/test/java/com/google/protobuf/UnknownEnumValueTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java",
"src/test/java/com/google/protobuf/UnknownFieldSetTest.java",
"src/test/java/com/google/protobuf/WellKnownTypesTest.java",
"src/test/java/com/google/protobuf/WireFormatTest.java",
Expand Down

0 comments on commit 36a2fe6

Please sign in to comment.