# GADTs for performance

**URL:** <https://discuss.ocaml.org/t/gadts-for-performance/6676>\
**Category:** Learning\
**Tags:** performance\
**Created:** [October 29, 2020, 1:39pm UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676 "2020-10-29T13:39:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanslade](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ryanslade/32/1676_2.png) [@ryanslade](https://discuss.ocaml.org/u/ryanslade)\
**Post date:** [October 29, 2020, 1:39pm UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676/1 "2020-10-29T13:39:46Z")

</div>

I’ve heard @Yaron_Minsky mention in a few talks and podcasts that GADTs can be used to improve performance, specifically around memory layout.

Does anyone have any examples of how this would work?

Is there a recording of this presentation anywhere? [http://www.cs.cmu.edu/afs/.cs.cmu.edu//Web/Posters/POP-YMinsky17.pdf](http://www.cs.cmu.edu/afs/.cs.cmu.edu//Web/Posters/POP-YMinsky17.pdf)

---

<div class="post-metadata">

**Author:** ![pmonson711](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/pmonson711/32/1691_2.png) [@pmonson711](https://discuss.ocaml.org/u/pmonson711)\
**Post date:** [October 29, 2020, 2:17pm UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676/2 "2020-10-29T14:17:15Z")

</div>

I think the details in this article really help understand [https://blog.janestreet.com/why-gadts-matter-for-performance/](https://blog.janestreet.com/why-gadts-matter-for-performance/).

Like so much of the performance focus, it’s not valid in most cases and is generally about controlling memory location.

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [October 30, 2020, 12:19am UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676/3 "2020-10-30T00:19:17Z")

</div>

I’m not sure about “not valid in most cases”. Controlling memory matters in many kinds of real-world applications. And I’m really excited about some work we’re doing for making it easier in OCaml. This talk fro Stephen Dolan is an exciting preview of that work.

[![](https://img.youtube.com/vi/RV-4Xddk0Yc/maxresdefault.jpg "Unboxed Types for OCaml") ](https://www.youtube.com/watch?v=RV-4Xddk0Yc)

There’s also an RFC worth reading.

> <https://github.com/ocaml/RFCs/blob/881b220adc1f358ab15f7743d5cd764222ab7d30/rfcs/unboxed-types.md>

---

<div class="post-metadata">

**Author:** ![Konstantin\_Olkhovski](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/konstantin_olkhovski/32/1494_2.png) [@Konstantin\_Olkhovski](https://discuss.ocaml.org/u/Konstantin_Olkhovski)\
**Post date:** [November 4, 2020, 2:03pm UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676/4 "2020-11-04T14:03:40Z")

</div>

@Yaron_Minsky It’s really exciting work! Is the plan to have this in ocaml trunk eventually?

---

<div class="post-metadata">

**Author:** ![xavierleroy](https://avatars.discourse-cdn.com/v4/letter/x/a9adbd/32.png) [@xavierleroy](https://discuss.ocaml.org/u/xavierleroy)\
**Post date:** [November 4, 2020, 5:36pm UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676/5 "2020-11-04T17:36:45Z")

</div>

The discussion on this RFC is very much open at this point. Personally, in reference to Stephen Dolan’s talk title, I prefer Lisp to C++.

---

<div class="post-metadata">

**Author:** ![coetry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/coetry/32/2351_2.png) [@coetry](https://discuss.ocaml.org/u/coetry)\
**Post date:** [November 4, 2020, 11:38pm UTC](https://discuss.ocaml.org/t/gadts-for-performance/6676/6 "2020-11-04T23:38:20Z")

</div>

I very much prefer Lisp as a language over C++, but being able to represent data in a more compact way for performance _when needed_ doesn’t sound like a bad idea to me! I’m purely speaking without any language design / implementation experience 😄
