Subscribe to the Ardan Labs Insider

You’ll get our FREE Video Series & special offers on upcoming training events along with notifications on our latest blog posts.

Included in your subscription
  • Access to our free video previews
  • Updates on our latest blog posts
  • Discounts on upcoming events

Valid email required.

Submit failed. Try again or message us directly at hello@ardanlabs.com.

Thank You for Subscribing

Check your email for confirmation.

Interfaces 101 : Heap Escape Ep. 2

Author image

Ardan Labs

Introduction

In episode 1, Miki had two functions that performed the similar operation, but returned different types. To refactor this, Miki rewrote both functions as a generic function that allowed him to specify the type to be returned during invocation. In some cases, the compiler may not recognise a type, thus, Miki gives a few pointers on manually telling a generic function which type to use. After demonstrating how to return different types with a generic function, Miki limited the types his generic function would accept with an interface.

In this video, Miki will take a closer look at the performance implications of interfaces since “there’s no such thing as a free lunch.” The first step he’ll take is to define a struct to represent weather and a function to return said type with a hard-coded value. Miki chose this example as it illustrates how a function’s variable can escape to the heap due to the use of interfaces. To better frame the previous statement, Go’s logging functions accept interface types for arguments and this is done to increase the universality of the logging function. Watch and learn how you can benchmark your code, view optimizations done by the compiler and pinpoint the variables being allocated to heap.

Things you will learn in this video

  • Performance implications of interfaces.
  • Go build flags to find code escaping to the heap.
  • Comments you can add to your functions that will prevent the compiler from inlining a function.
  • Performance impact of allocating to heap.

Video

Go Training

We have taught Go to thousands of developers all around the world since 2014. There is no other company that has been doing it longer and our material has proven to help jump start developers 6 to 12 months ahead of their knowledge of Go. We know what knowledge developers need in order to be productive and efficient when writing software in Go.

Our classes are perfect for both experienced and beginning engineers. We start every class from the beginning and get very detailed about the internals, mechanics, specification, guidelines, best practices and design philosophies. We cover a lot about "if performance matters" with a focus on mechanical sympathy, data oriented design, decoupling and writing production software.

Capital One
Cisco
Visa
Teradata
Red Ventures

Interested in Ultimate Go Corporate Training and special pricing?

Let’s Talk Corporate Training!

Join Our Online
Education Program

Our courses have been designed from training over 30,000 engineers since 2013, and they go beyond just being a language course. Our goal is to challenge every student to think about what they are doing and why.