# Interfaces 101 : Heap Escape Ep. 2

DevFeed: [Interfaces 101 : Heap Escape Ep. 2](<https://devfeed.tech/articles/interfaces-101-heap-escape-ep-2-22215.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/02/interfaces-101-heap-escape.html>)

Published: 2023-02-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [interface](<https://devfeed.tech/topics/interface.md>), [Software](<https://devfeed.tech/topics/software.md>), [escape analysis](<https://devfeed.tech/topics/escape-analysis.md>), [inlining](<https://devfeed.tech/topics/inlining.md>), [Type Parameter](<https://devfeed.tech/topics/type-parameter.md>), [Type Argument](<https://devfeed.tech/topics/type-argument.md>), [data type](<https://devfeed.tech/topics/data-type.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [build](<https://devfeed.tech/tags/build.md>), [escape-heap](<https://devfeed.tech/tags/escape-heap.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [heap](<https://devfeed.tech/tags/heap.md>), [inlining](<https://devfeed.tech/tags/inlining.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [log-variables](<https://devfeed.tech/tags/log-variables.md>), [optimizations](<https://devfeed.tech/tags/optimizations.md>), [performance](<https://devfeed.tech/tags/performance.md>), [struct](<https://devfeed.tech/tags/struct.md>), [variable](<https://devfeed.tech/tags/variable.md>), [variables](<https://devfeed.tech/tags/variables.md>)

## AI overview

The episode examines how Go interfaces can affect performance by causing a function variable to escape to the heap. Using a weather struct and a function returning it, Miki demonstrates benchmarking, compiler optimization output, and Go build flags for identifying heap allocations. It also covers function comments that prevent compiler inlining and notes that Go logging functions accept interface arguments to make them more universal. The excerpt describes the episode's planned topics but does not provide benchmark results or quantify performance costs.

## Source excerpt

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.