On Static Dispatch vs Dynamic Dispatch

I think the standard library should provide a mechanism for developers to decide whether to use static or dynamic dispatch. Both of these methods have their own usage scenarios and should not be limited to a fixed approach.

I have optimized AllocatorTrait in vftrait to allow for both static and dynamic dispatch. vftrait/src/traits/allocator.zig at feature/traits · Verafahn/vftrait

I think the standard library should also need a similar approach to give the caller the right to choose. By the way, Rust seems to pass on the choice to the caller through the keyword dyn.

In addition, I think providing static distribution for problem Smaller Io interface (Io-core) is a good solution. Due to the lazy analysis feature of Zig code itself, unused interfaces will not occupy the memory of virtual table pointers like dynamic dispatch.

1 Like