|
From PR 1308:
Summary
Remove all uses of reflect.Value.MethodByName since it prevents dead code elimination. This causes binaries built with the mongodb/mongo-go-driver library to be larger than they need to be.
All occurrences of reflect.Value.MethodByName are replaced with type assertions.
Source: https://go.dev/src/cmd/link/internal/ld/deadcode.go#L293
Background & Motivation
Reduce the size of binaries built with mongodb/mongo-go-driver.
From the linked deadcode.go code:
// The third case is handled by looking to see if any of:
|
// - reflect.Value.Method or MethodByName is reachable
|
// - reflect.Type.Method or MethodByName is called (through the
|
// REFLECTMETHOD attribute marked by the compiler).
|
//
|
// If any of these happen, all bets are off and all exported methods
|
// of reachable types are marked reachable.
|
TLDR: If your code calls reflect.Type.Method or reflect.Type.MethodByName, the linker can't prune any unreachable code and your compiled binary may be inflated. Never use those functions if you can avoid it.
|