You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
coreAreTypesCompatible currently uses two manually maintained
stacks to traverse two types to compare. The original idea was
that using stacks would somehow be more efficient or it'd be
easier to understand than the recursive approach. Time has shown
that this was probably not true. Using the stacks is both harder
to understand and probably less performant than using recursion.
This is because the runtime maintains a stack for us, which can
be reused across many invocations. Allocating on the (goroutine)
stack is also incredibly cheap.
Rewrite coreAreTypesCompatible to use recursion to traverse the
two types. Instead of using walkType we simply open code the
switch cases for Pointer, Array and FuncProto. This isn't much
code and gets rid of a bunch of complexity and allocations,
especially for FuncParam.
The depth check is removed completely. It's a hold over from
libbpf, which probably uses it to avoid stack overflow. This
isn't necessary in Go, since overflowing the stack is guaranteed
to panic. Instead, we deal with cyclical types by maintaining
a visited map.
Signed-off-by: Lorenz Bauer <[email protected]>
0 commit comments