Merge pull request #329 from haberman/benchmark-ads-descriptor

Added benchmark for loading ads descriptor.
pull/13171/head
Joshua Haberman 4 years ago committed by GitHub
commit 6322d1d72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      WORKSPACE
  2. 6
      benchmarks/BUILD
  3. 29
      benchmarks/BUILD.googleapis
  4. 68
      benchmarks/benchmark.cc
  5. 3
      cmake/make_cmakelists.py
  6. 7
      upb/def.c
  7. 1
      upb/def.h

@ -1,6 +1,7 @@
workspace(name = "upb")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("//bazel:workspace_deps.bzl", "upb_deps")
upb_deps()
@ -37,3 +38,11 @@ http_archive(
strip_prefix = "benchmark-16703ff83c1ae6d53e5155df3bb3ab0bc96083be",
sha256 = "59f918c8ccd4d74b6ac43484467b500f1d64b40cc1010daa055375b322a43ba3",
)
new_git_repository(
name = "com_google_googleapis",
remote = "https://github.com/googleapis/googleapis.git",
branch = "master",
build_file = "//benchmarks:BUILD.googleapis",
patch_cmds = ["find google -type f -name BUILD.bazel -delete"],
)

@ -21,6 +21,11 @@ upb_proto_reflection_library(
deps = [":benchmark_descriptor_proto"],
)
upb_proto_reflection_library(
name = "ads_upb_proto_reflection",
deps = ["@com_google_googleapis//:ads_proto"],
)
cc_proto_library(
name = "benchmark_descriptor_cc_proto",
deps = [":benchmark_descriptor_proto"],
@ -45,6 +50,7 @@ cc_binary(
":benchmark_descriptor_sv_cc_proto",
":benchmark_descriptor_upb_proto",
":benchmark_descriptor_upb_proto_reflection",
":ads_upb_proto_reflection",
"//:descriptor_upb_proto",
"//:reflection",
"@com_github_google_benchmark//:benchmark_main",

@ -0,0 +1,29 @@
load(
"@rules_proto//proto:defs.bzl",
"proto_library",
)
proto_library(
name = "ads_proto",
srcs = glob([
"google/ads/googleads/v5/**/*.proto",
"google/api/**/*.proto",
"google/rpc/**/*.proto",
"google/longrunning/**/*.proto",
"google/logging/**/*.proto",
]),
#srcs = ["google/ads/googleads/v5/services/google_ads_service.proto"],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:field_mask_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:api_proto",
"@com_google_protobuf//:type_proto",
"@com_google_protobuf//:wrappers_proto",
],
)

@ -9,9 +9,10 @@
#include "benchmarks/descriptor_sv.pb.h"
// For for benchmarks of building descriptors.
#include "google/protobuf/descriptor.upb.h"
#include "google/ads/googleads/v5/services/google_ads_service.upbdefs.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.upb.h"
#include "google/protobuf/descriptor.upbdefs.h"
#include "upb/def.hpp"
upb_strview descriptor = benchmarks_descriptor_proto_upbdefinit.descriptor;
@ -20,6 +21,16 @@ namespace protobuf = ::google::protobuf;
/* A buffer big enough to parse descriptor.proto without going to heap. */
char buf[65535];
void CollectFileDescriptors(const upb_def_init* file,
std::vector<upb_strview>& serialized_files,
std::unordered_set<const upb_def_init*>& seen) {
if (!seen.insert(file).second) return;
for (upb_def_init **deps = file->deps; *deps; deps++) {
CollectFileDescriptors(*deps, serialized_files, seen);
}
serialized_files.push_back(file->descriptor);
}
static void BM_ArenaOneAlloc(benchmark::State& state) {
for (auto _ : state) {
upb_arena* arena = upb_arena_new();
@ -39,22 +50,28 @@ static void BM_ArenaInitialBlockOneAlloc(benchmark::State& state) {
BENCHMARK(BM_ArenaInitialBlockOneAlloc);
static void BM_LoadDescriptor_Upb(benchmark::State& state) {
size_t bytes_per_iter;
for (auto _ : state) {
upb::SymbolTable symtab;
upb::Arena arena;
google_protobuf_FileDescriptorProto* file_proto =
google_protobuf_FileDescriptorProto_parse(descriptor.data,
descriptor.size, arena.ptr());
upb::FileDefPtr file_def = symtab.AddFile(file_proto, NULL);
if (!file_def) {
printf("Failed to add file.\n");
exit(1);
}
google_protobuf_DescriptorProto_getmsgdef(symtab.ptr());
bytes_per_iter = _upb_symtab_bytesloaded(symtab.ptr());
}
state.SetBytesProcessed(state.iterations() * descriptor.size);
}
BENCHMARK(BM_LoadDescriptor_Upb);
static void BM_LoadAdsDescriptor_Upb(benchmark::State& state) {
size_t bytes_per_iter;
for (auto _ : state) {
upb::SymbolTable symtab;
google_ads_googleads_v5_services_SearchGoogleAdsRequest_getmsgdef(
symtab.ptr());
bytes_per_iter = _upb_symtab_bytesloaded(symtab.ptr());
}
state.SetBytesProcessed(state.iterations() * bytes_per_iter);
}
BENCHMARK(BM_LoadAdsDescriptor_Upb);
static void BM_LoadDescriptor_Proto2(benchmark::State& state) {
for (auto _ : state) {
protobuf::Arena arena;
@ -73,6 +90,35 @@ static void BM_LoadDescriptor_Proto2(benchmark::State& state) {
}
BENCHMARK(BM_LoadDescriptor_Proto2);
static void BM_LoadAdsDescriptor_Proto2(benchmark::State& state) {
extern upb_def_init google_ads_googleads_v5_services_google_ads_service_proto_upbdefinit;
std::vector<upb_strview> serialized_files;
std::unordered_set<const upb_def_init*> seen_files;
CollectFileDescriptors(
&google_ads_googleads_v5_services_google_ads_service_proto_upbdefinit,
serialized_files, seen_files);
size_t bytes_per_iter;
for (auto _ : state) {
bytes_per_iter = 0;
protobuf::Arena arena;
protobuf::DescriptorPool pool;
for (auto file : serialized_files) {
protobuf::StringPiece input(file.data, file.size);
auto proto = protobuf::Arena::CreateMessage<protobuf::FileDescriptorProto>(
&arena);
bool ok = proto->ParseFrom<protobuf::MessageLite::kMergePartial>(input) &&
pool.BuildFile(*proto) != nullptr;
if (!ok) {
printf("Failed to add file.\n");
exit(1);
}
bytes_per_iter += input.size();
}
}
state.SetBytesProcessed(state.iterations() * bytes_per_iter);
}
BENCHMARK(BM_LoadAdsDescriptor_Proto2);
static void BM_Parse_Upb_FileDesc_WithArena(benchmark::State& state) {
size_t bytes = 0;
for (auto _ : state) {

@ -177,6 +177,9 @@ class WorkspaceFileFunctions(object):
def git_repository(self, **kwargs):
pass
def new_git_repository(self, **kwargs):
pass
def bazel_version_repository(self, **kwargs):
pass

@ -118,6 +118,7 @@ struct upb_symtab {
upb_arena *arena;
upb_strtable syms; /* full_name -> packed def ptr */
upb_strtable files; /* file_name -> upb_filedef* */
size_t bytes_loaded;
};
/* Inside a symtab we store tagged pointers to specific def types. */
@ -2084,6 +2085,7 @@ upb_symtab *upb_symtab_new(void) {
}
s->arena = upb_arena_new();
s->bytes_loaded = 0;
alloc = upb_arena_alloc(s->arena);
if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, 32, alloc) ||
@ -2187,6 +2189,7 @@ bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init) {
file = google_protobuf_FileDescriptorProto_parse(
init->descriptor.data, init->descriptor.size, arena);
s->bytes_loaded += init->descriptor.size;
if (!file) {
upb_status_seterrf(
@ -2209,5 +2212,9 @@ err:
return false;
}
size_t _upb_symtab_bytesloaded(const upb_symtab *s) {
return s->bytes_loaded;
}
#undef CHK
#undef CHK_OOM

@ -293,6 +293,7 @@ int upb_symtab_filecount(const upb_symtab *s);
const upb_filedef *upb_symtab_addfile(
upb_symtab *s, const google_protobuf_FileDescriptorProto *file,
upb_status *status);
size_t _upb_symtab_bytesloaded(const upb_symtab *s);
/* For generated code only: loads a generated descriptor. */
typedef struct upb_def_init {

Loading…
Cancel
Save