Again back to comptime vtables

I may be asking a million time question.
New IO has tenish things (30+ roughly) in vtable and it’s still runtime overhead. Some may say it’s not meaningful because it goes to the buffer first. I say Linux may respond from a page cash and it could be visible.

I have seen a proposal, but it does de virtual only if a single IO is used (which might never happen for most of the large software).

Why does the team resist so hard against compile time interfaces?

is there a large concern to increase a binary size? Using a single implementation achieves the same result as runtime interfaces and its de virtualization.

What Do I miss?

Does it give little to no benefit to define all the used implementations of an interface in compile time?

1 Like

This only reflects my understanding of what the maintainer of the language have said or what I’ve been able to gather through interaction with them or from reading discussion where they were involved, so take it with a pinch of salt.

But one of the main design element of Zig, is careful use of purposeful friction throughout the language and idioms, to encourage and support better craftsmanship. This boils down to “Making it easy to do the right thing, and involved to do the “””“bad”“”" thing" This is obviously a simplification, but i believe it to be the main reason why there isn’t compiler support for compile time interfaces.

Compile time interfaces, are totally feasible, it’s a mostly solved problem, but the reason they haven’t implemented it, is because in 90% of cases VTables are just not the best tool for the job, they sure might be the most convenient, but they bloat the software unnecessarily without ever providing any value. YAGNI and KISS are good principles, and Zig’s design purposefully adds friction there, to give you the opportunity to reflect on whether that’s the best tool for the job.

It’s a common theme across the language. Now as for IO and the proposal for restricted pointer type, if I recall correctly, the goal of restricted pointer type, is to help and support VTable based interface, and help devirtualize better and also provide a way to statically infer maximal stack usage, 2 very nice feature to support the new IO/Reader/Writer/Async/Await userpace implementation. Will those solve the current issues with IO or Vtable in general ? I can’t say for sure, but they look like a good step in the right direction :slight_smile:

2 Likes

Yes, I do agree the proposal is a good additional to the current vector.

But having anytype in the language doesn’t fit everything together in my head.