Skip to content

Commit

Permalink
wasm: remove non-representative and redundant benchmarks. (#15203)
Browse files Browse the repository at this point in the history
The "json_serialize_arena" test was non-representative, and it was running
out of memory in WasmVM during benchmarks, leading to invalid results.

The "json_deserialize_arena" test was measuring exactly the same process as
the "json_deserialize" test, so it was redundant.

The "json_serialize_deserialize" test was a combinantion of "json_serialize"
and "json_deserialize" tests, so it was redundant.

While there, make sure that inputs are not used as outputs, and vice-versa.

Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored Mar 3, 2021
1 parent 5e0a9e2 commit 8e33342
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
54 changes: 15 additions & 39 deletions test/extensions/bootstrap/wasm/test_data/speed_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ START_WASM_PLUGIN(WasmSpeedCpp)

int xDoNotRemove = 0;

google::protobuf::Arena arena;
google::protobuf::Struct test_proto;

google::protobuf::Struct args;
google::protobuf::Struct* args_arena =
google::protobuf::Arena::CreateMessage<google::protobuf::Struct>(&arena);
std::string configuration = R"EOF(
const std::string test_json = R"EOF(
{
"NAME":"test_pod",
"NAMESPACE":"test_namespace",
Expand All @@ -43,9 +40,6 @@ std::string configuration = R"EOF(
}
)EOF";

// google::protobuf::Struct a;
// google::protobuf::util::JsonStringToMessage(configuration+'hfdjfhkjhdskhjk', a);

const static char encodeLookup[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const static char padCharacter = '=';
Expand Down Expand Up @@ -242,47 +236,34 @@ void modify_metadata1000_test() {
}
}

void json_serialize_test() { google::protobuf::util::JsonStringToMessage(configuration, &args); }

void json_serialize_arena_test() {
google::protobuf::util::JsonStringToMessage(configuration, args_arena);
void json_serialize_test() {
google::protobuf::Struct proto;
google::protobuf::util::JsonStringToMessage(test_json, &proto);
}

void json_deserialize_test() {
std::string json;
google::protobuf::util::MessageToJsonString(args, &json);
google::protobuf::util::MessageToJsonString(test_proto, &json);
xDoNotRemove += json.size();
}

void json_deserialize_arena_test() {
std::string json;
google::protobuf::util::MessageToJsonString(*args_arena, &json);
}

void json_deserialize_empty_test() {
std::string json;
google::protobuf::Struct empty;
google::protobuf::util::MessageToJsonString(empty, &json);
xDoNotRemove = json.size();
}

void json_serialize_deserialize_test() {
std::string json;
google::protobuf::Struct proto;
google::protobuf::util::JsonStringToMessage(configuration, &proto);
google::protobuf::util::MessageToJsonString(proto, &json);
xDoNotRemove = json.size();
}

void convert_to_filter_state_test() {
auto start = reinterpret_cast<uint8_t*>(&*configuration.begin());
auto end = start + configuration.size();
std::string encoded_config = base64Encode(start, end);
auto start = reinterpret_cast<const uint8_t*>(&*test_json.begin());
auto end = start + test_json.size();
std::string encoded_json = base64Encode(start, end);
std::vector<uint8_t> decoded;
base64Decode(encoded_config, &decoded);
std::string decoded_config(decoded.begin(), decoded.end());
google::protobuf::util::JsonStringToMessage(decoded_config, &args);
auto bytes = args.SerializeAsString();
base64Decode(encoded_json, &decoded);
std::string decoded_json(decoded.begin(), decoded.end());
google::protobuf::Struct proto;
google::protobuf::util::JsonStringToMessage(decoded_json, &proto);
auto bytes = proto.SerializeAsString();
setFilterStateStringValue("wasm_request_set_key", bytes);
}

Expand Down Expand Up @@ -320,16 +301,11 @@ WASM_EXPORT(uint32_t, proxy_on_vm_start, (uint32_t, uint32_t configuration_size)
test_fn = &modify_metadata1000_test;
} else if (configuration == "json_serialize") {
test_fn = &json_serialize_test;
} else if (configuration == "json_serialize_arena") {
test_fn = &json_serialize_arena_test;
} else if (configuration == "json_deserialize") {
google::protobuf::util::JsonStringToMessage(test_json, &test_proto);
test_fn = &json_deserialize_test;
} else if (configuration == "json_deserialize_empty") {
test_fn = &json_deserialize_empty_test;
} else if (configuration == "json_deserialize_arena") {
test_fn = &json_deserialize_arena_test;
} else if (configuration == "json_serialize_deserialize") {
test_fn = &json_serialize_deserialize_test;
} else if (configuration == "convert_to_filter_state") {
test_fn = &convert_to_filter_state_test;
} else {
Expand Down
3 changes: 0 additions & 3 deletions test/extensions/bootstrap/wasm/wasm_speed_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ B(grpc_service1000)
B(modify_metadata)
B(modify_metadata1000)
B(json_serialize)
B(json_serialize_arena)
B(json_deserialize)
B(json_deserialize_arena)
B(json_deserialize_empty)
B(json_serialize_deserialize)
B(convert_to_filter_state)

} // namespace Wasm
Expand Down

0 comments on commit 8e33342

Please sign in to comment.