FAQ

Interface is good, but seems good things do come for free. So why
interface will slow down a go program, more 50 times slower?
Interfaces are like virtual methods in C++. Calls to concrete types get
resolved by the compiler, while calls to interfaces require a vtable-like
lookup which is resolved at run time. In pseudo-code, you can think of it
like:

Concrete type call:

CALL some_function ; where some_function is a constant address

Interface call:

LOAD methods_table
LOOKUP methods_table method_name
CALL result_of_lookup

TLDR: Run time polymorphism does not come for free, because it has the cost
of an extra indirection regardless of the language.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 5 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 27, '14 at 2:59a
activeApr 27, '14 at 12:09p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase