# Advice to make getfield(::NamedTuple, ::Symbol) typestable

**URL:** <https://discourse.julialang.org/t/advice-to-make-getfield-namedtuple-symbol-typestable/78340>\
**Category:** Performance\
**Created:** [March 23, 2022, 4:00pm UTC](https://discourse.julialang.org/t/advice-to-make-getfield-namedtuple-symbol-typestable/78340 "2022-03-23T16:00:29Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 24, 2022, 2:08pm UTC](https://discourse.julialang.org/t/advice-to-make-getfield-namedtuple-symbol-typestable/78340/8 "2022-03-24T14:08:16Z")

</div>

> [@ianfiske](#):
>
> `@code_warntype` shows a type instability from `getindex` on that NamedTuple in the slow call

`@code_warntype` is misleading you here. This is exactly the same issue as trying to do `@code_warntype pair.first` here: [Accessing the field of `Pair` seems to be type-unstable - #4 by rdeits](https://discourse.julialang.org/t/accessing-the-field-of-pair-seems-to-be-type-unstable/78045/4)

Edit: Although if you really are passing a `Symbol` down from your outermost function, then the type instability is real (even if your first example doesn’t necessarily show it). If that’s the case, then the `Val` approach seems reasonable to me.

---

_[View the full topic](https://discourse.julialang.org/t/advice-to-make-getfield-namedtuple-symbol-typestable/78340)._
