vdl: Add fastpath to vdl.Convertible for same types.
The astute reader will notice that technically we're at 297us for
the 1B rpc, on my machine, which means we're done! :)
$ jiri go test -bench '(1B|Vom)' v.io/x/ref/runtime/internal/rpc/bench
old ns/op new ns/op delta
____1B 308239 297635 -3.44%
____1B_ClientTPCav 547329 534398 -2.36%
____1B_ServerTPCav 593025 583766 -1.56%
____1B_ProxiedServer 413618 404926 -2.10%
____1_chunk_____1B 402684 401834 -0.21%
___10_chunk_____1B 944269 923477 -2.20%
__100_chunk_____1B 6056300 6036839 -0.32%
___1K_chunk_____1B 56669014 55292847 -2.43%
__per_chunk____1B 55035 53107 -3.50%
VomEncodeRequest 4939 4860 -1.60%
VomDecodeRequest 11472 10285 -10.35%
VomEncodeResponse 4290 4324 +0.79%
VomDecodeResponse 6906 6171 -10.64%
Change-Id: I1d1e7a775882725f2496b3fe852009e09620d084
diff --git a/vdl/compatible.go b/vdl/compatible.go
index 67dc852..d0a698d 100644
--- a/vdl/compatible.go
+++ b/vdl/compatible.go
@@ -64,11 +64,9 @@
//
// union{A string} <-> string <-> union{B string}
func Compatible(a, b *Type) bool {
- if a.Kind() == Optional {
- a = a.Elem()
- }
- if b.Kind() == Optional {
- b = b.Elem()
+ a, b = a.NonOptional(), b.NonOptional()
+ if a == b {
+ return true // fastpath for common case
}
key := compatKey(a, b)
if compat, ok := compatCache.lookup(key); ok {