Merged common encode tag paths.
diff --git a/benchmark.py b/benchmark.py
index 9c59674..98c0088 100755
--- a/benchmark.py
+++ b/benchmark.py
@@ -7,7 +7,7 @@
def Run(cmd):
subprocess.check_call(cmd, shell=True)
-def RunAgainstBranch(branch, outfile, runs=12):
+def RunAgainstBranch(branch, outbase, runs=12):
tmpfile = "/tmp/bench-output.json"
Run("rm -rf {}".format(tmpfile))
Run("git checkout {}".format(branch))
@@ -15,10 +15,13 @@
Run("./bazel-bin/benchmark --benchmark_out_format=json --benchmark_out={} --benchmark_repetitions={}".format(tmpfile, runs))
+ Run("bazel build -c opt --copt=-g :conformance_upb")
+ Run("cp -f bazel-bin/conformance_upb {}.bin".format(outbase))
+
with open(tmpfile) as f:
bench_json = json.load(f)
- with open(outfile, "w") as f:
+ with open(outbase + ".txt", "w") as f:
for run in bench_json["benchmarks"]:
name = re.sub(r'^BM_', 'Benchmark', run["name"])
if name.endswith("_mean") or name.endswith("_median") or name.endswith("_stddev"):
@@ -26,7 +29,17 @@
values = (name, run["iterations"], run["cpu_time"])
print("{} {} {} ns/op".format(*values), file=f)
-RunAgainstBranch("master", "/tmp/old.txt")
-RunAgainstBranch("decoder", "/tmp/new.txt")
+RunAgainstBranch("6e140c267cc9bf6a4ef89d3f9a842209d7537599", "/tmp/old")
+RunAgainstBranch("encoder", "/tmp/new")
+
+print()
+print()
Run("~/go/bin/benchstat /tmp/old.txt /tmp/new.txt")
+
+print()
+print()
+
+Run("objcopy --strip-debug /tmp/old.bin /tmp/old.bin.stripped")
+Run("objcopy --strip-debug /tmp/new.bin /tmp/new.bin.stripped")
+Run("~/code/bloaty/bloaty /tmp/new.bin.stripped -- /tmp/old.bin.stripped --debug-file=/tmp/old.bin --debug-file=/tmp/new.bin -d compileunits,symbols")
diff --git a/upb/encode.c b/upb/encode.c
index bebb5cd..9327533 100644
--- a/upb/encode.c
+++ b/upb/encode.c
@@ -154,15 +154,18 @@
const upb_msglayout *m, const upb_msglayout_field *f,
bool skip_zero_value) {
const char *field_mem = _field_mem;
-#define CASE(ctype, type, wire_type, encodeval) do { \
- ctype val = *(ctype*)field_mem; \
- if (skip_zero_value && val == 0) { \
- return; \
- } \
- encode_ ## type(e, encodeval); \
- encode_tag(e, f->number, wire_type); \
- return; \
-} while(0)
+ int wire_type;
+
+#define CASE(ctype, type, wtype, encodeval) \
+ { \
+ ctype val = *(ctype *)field_mem; \
+ if (skip_zero_value && val == 0) { \
+ return; \
+ } \
+ encode_##type(e, encodeval); \
+ wire_type = wtype; \
+ break; \
+ }
switch (f->descriptortype) {
case UPB_DESCRIPTOR_TYPE_DOUBLE:
@@ -197,8 +200,8 @@
}
encode_bytes(e, view.data, view.size);
encode_varint(e, view.size);
- encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
- return;
+ wire_type = UPB_WIRE_TYPE_DELIMITED;
+ break;
}
case UPB_DESCRIPTOR_TYPE_GROUP: {
size_t size;
@@ -209,8 +212,8 @@
}
encode_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP);
encode_message(e, submsg, subm, &size);
- encode_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP);
- return;
+ wire_type = UPB_WIRE_TYPE_START_GROUP;
+ break;
}
case UPB_DESCRIPTOR_TYPE_MESSAGE: {
size_t size;
@@ -221,12 +224,13 @@
}
encode_message(e, submsg, subm, &size);
encode_varint(e, size);
- encode_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
- return;
+ wire_type = UPB_WIRE_TYPE_DELIMITED;
+ break;
}
}
#undef CASE
- UPB_UNREACHABLE();
+
+ encode_tag(e, f->number, wire_type);
}
static void encode_array(upb_encstate *e, const char *field_mem,