# \#optimization

**URL:** https://discuss.ocaml.org/tag/optimization/84.md

[Latest](https://discuss.ocaml.org/latest.md) · [Categories](https://discuss.ocaml.org/categories.md) · [Tags](https://discuss.ocaml.org/tags.md)

---

## [\[BLOG\] Flambda2 Ep. 4: How to write a purely functional compiler, by OCamlPro](https://discuss.ocaml.org/t/blog-flambda2-ep-4-how-to-write-a-purely-functional-compiler-by-ocamlpro/16512)

<div class="topic-metadata">

**Author:** [@OCamlPro](https://discuss.ocaml.org/u/OCamlPro)\
**Replies:** 6\
**Last updated:** [May 30, 2025, 10:27am UTC](https://discuss.ocaml.org/t/blog-flambda2-ep-4-how-to-write-a-purely-functional-compiler-by-ocamlpro/16512 "2025-05-30T10:27:12Z")

</div>

Greetings Cameleers! We’re back with another deep dive into the Flambda2 Optimizing Compiler! Our latest entry in the Flambda2 Snippets blog series is out ! Flambda2 Ep. 4: How to write a purely functional compiler Be…

---

## [\[BLOG\] Flambda2 Ep. 2: Loopifying Tail-Recursive Functions, by OCamlPro](https://discuss.ocaml.org/t/blog-flambda2-ep-2-loopifying-tail-recursive-functions-by-ocamlpro/14758)

<div class="topic-metadata">

**Author:** [@OCamlPro](https://discuss.ocaml.org/u/OCamlPro)\
**Replies:** 3\
**Last updated:** [June 10, 2024, 4:29pm UTC](https://discuss.ocaml.org/t/blog-flambda2-ep-2-loopifying-tail-recursive-functions-by-ocamlpro/14758 "2024-06-10T16:29:00Z")

</div>

Greetings Cameleers, We would like to share with you our latest Flambda2 Snippet: Flambda2 Ep. 2: Loopifying Tail-Recursive Functions! Indeed, today’s topic is what is called Loopify, one of the many optimisation algor…

---

## [Int32 optimization puzzle](https://discuss.ocaml.org/t/int32-optimization-puzzle/13369)

<div class="topic-metadata">

**Author:** [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Replies:** 3\
**Last updated:** [November 8, 2023, 9:01pm UTC](https://discuss.ocaml.org/t/int32-optimization-puzzle/13369 "2023-11-08T21:01:52Z")

</div>

I have the following code of which I don’t quite understand the performance behaviour. This is a CRC-32 computation made with int32 OCaml integers (I would like to get rid of this int32 unboxing hack in a library, espe…

---

## [Static analysis in Flambda 2 - Talks at the Cambium Seminar](https://discuss.ocaml.org/t/static-analysis-in-flambda-2-talks-at-the-cambium-seminar/12913)

<div class="topic-metadata">

**Author:** [@OCamlPro](https://discuss.ocaml.org/u/OCamlPro)\
**Replies:** 2\
**Last updated:** [August 29, 2023, 8:59am UTC](https://discuss.ocaml.org/t/static-analysis-in-flambda-2-talks-at-the-cambium-seminar/12913 "2023-08-29T08:59:57Z")

</div>

We are delighted to announce that there is a seminar in the Cambium team at Inria today at 11am CEST, Paris, related to Flambda 2. The seminar is accessible online at seminaire-cambium This talk follows our previous ta…

---

## [\[ANN\] ppx\_update 0.81](https://discuss.ocaml.org/t/ann-ppx-update-0-81/12794)

<div class="topic-metadata">

**Author:** [@bluddy](https://discuss.ocaml.org/u/bluddy)\
**Replies:** 0\
**Last updated:** [August 10, 2023, 2:42pm UTC](https://discuss.ocaml.org/t/ann-ppx-update-0-81/12794 "2023-08-10T14:42:09Z")

</div>

Hi guys. I wanted to let you know about ppx\_update. This is a small utility ppx that rewrites some record update expressions to make them more efficient. When updating the contents of a record functionally, one might wa…

---

## [Annotation to assert no GC run (allocation?) in a function](https://discuss.ocaml.org/t/annotation-to-assert-no-gc-run-allocation-in-a-function/10462)

<div class="topic-metadata">

**Author:** [@orbitz](https://discuss.ocaml.org/u/orbitz)\
**Replies:** 6\
**Last updated:** [September 14, 2022, 6:36pm UTC](https://discuss.ocaml.org/t/annotation-to-assert-no-gc-run-allocation-in-a-function/10462 "2022-09-14T18:36:28Z")

</div>

I was wondering: Would it be possible to have some sort of annotation to assert that a GC will not run in some function, or block, of code? Would that be useful? There are is various bits of knowledge about how to con…

---

## [Local functions and performance](https://discuss.ocaml.org/t/local-functions-and-performance/9644)

<div class="topic-metadata">

**Author:** [@threepwood](https://discuss.ocaml.org/u/threepwood)\
**Replies:** 6\
**Last updated:** [April 11, 2022, 8:07am UTC](https://discuss.ocaml.org/t/local-functions-and-performance/9644 "2022-04-11T08:07:52Z")

</div>

Very basic question: is there a perfomance cost to the below idiom where a non-public recursive function implementing a loop / traversal of some kind takes some of its arguments from the context rather than explicitly? O…

---

## [Is there a faster way to calculate the 2D Minimum Spanning Tree?](https://discuss.ocaml.org/t/is-there-a-faster-way-to-calculate-the-2d-minimum-spanning-tree/9628)

<div class="topic-metadata">

**Author:** [@Butanium](https://discuss.ocaml.org/u/Butanium)\
**Replies:** 1\
**Last updated:** [April 1, 2022, 8:03pm UTC](https://discuss.ocaml.org/t/is-there-a-faster-way-to-calculate-the-2d-minimum-spanning-tree/9628 "2022-04-01T20:03:54Z")

</div>

Hi, I’m implementing a MST for a set of 2D points, here is my current code using the Prim agorithm : module IntSet = Set.Make (Int) let prim\_alg adj\_matrix city\_count = let eval a b = adj\_matrix.(a).(b) in let in…

---

## [What Lambda flags do you usually use to speed up your code?](https://discuss.ocaml.org/t/what-lambda-flags-do-you-usually-use-to-speed-up-your-code/9241)

<div class="topic-metadata">

**Author:** [@Butanium](https://discuss.ocaml.org/u/Butanium)\
**Replies:** 6\
**Last updated:** [February 3, 2022, 8:19pm UTC](https://discuss.ocaml.org/t/what-lambda-flags-do-you-usually-use-to-speed-up-your-code/9241 "2022-02-03T20:19:19Z")

</div>

I’d like to compare my program with the one used in a paper which was coded in cpp. As I know that they made everything to make their code optimized, I’d like to speed up mine the more I can in order to have a decent co…

---

## ["not" defined by matching vs "external"](https://discuss.ocaml.org/t/not-defined-by-matching-vs-external/4043)

<div class="topic-metadata">

**Author:** [@SkySkimmer](https://discuss.ocaml.org/u/SkySkimmer)\
**Replies:** 4\
**Last updated:** [July 17, 2019, 1:48pm UTC](https://discuss.ocaml.org/t/not-defined-by-matching-vs-external/4043 "2019-07-17T13:48:55Z")

</div>

Consider the following 2 definitions of not: let external\_not x = not x let match\_not = function true -\> false | false -\> true Godbolt https://godbolt.org/z/IJJAoU says we get different assembly: camlExample\_\_exter…

---

## [What is the fastest way to compute the weighted Jaccard index in OCaml?](https://discuss.ocaml.org/t/what-is-the-fastest-way-to-compute-the-weighted-jaccard-index-in-ocaml/3703)

<div class="topic-metadata">

**Author:** [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Replies:** 15\
**Last updated:** [April 25, 2019, 6:49am UTC](https://discuss.ocaml.org/t/what-is-the-fastest-way-to-compute-the-weighted-jaccard-index-in-ocaml/3703 "2019-04-25T06:49:20Z")

</div>

Hello, What is the most efficient way to compute this: given two sparse integer vectors A and B, we want to compute: J\_w(A,B) = |AnB| / (|A| + |B| - |AnB|) With |A| being sum(a\_i); i.e. the sum of all feature counts. …

---

## [Will the native compiler ever optimize memory layout of compound types?](https://discuss.ocaml.org/t/will-the-native-compiler-ever-optimize-memory-layout-of-compound-types/3394)

<div class="topic-metadata">

**Author:** [@mylincode](https://discuss.ocaml.org/u/mylincode)\
**Replies:** 0\
**Last updated:** [February 21, 2019, 10:45pm UTC](https://discuss.ocaml.org/t/will-the-native-compiler-ever-optimize-memory-layout-of-compound-types/3394 "2019-02-21T22:45:28Z")

</div>

Say I have the type int list option. As I understand the current operation of ocamlopt, a value such as Some \[5\] will have a memory layout like this: First, there will be an on-heap variant instance (for the option par…

---

## [For machine-learning people: nlopt-ocaml is quite nice](https://discuss.ocaml.org/t/for-machine-learning-people-nlopt-ocaml-is-quite-nice/3387)

<div class="topic-metadata">

**Author:** [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Replies:** 0\
**Last updated:** [February 21, 2019, 6:59am UTC](https://discuss.ocaml.org/t/for-machine-learning-people-nlopt-ocaml-is-quite-nice/3387 "2019-02-21T06:59:00Z")

</div>

Hello, This library is a real time-saver when doing parameter optimization for machine learning models (hyper parameter search). Since it can smartly stop an optimization process, it is really faster than doing a g…

---

## [Finalizers, value lifetimes and \`Sys.opaque\_identity\`](https://discuss.ocaml.org/t/finalizers-value-lifetimes-and-sys-opaque-identity/2750)

<div class="topic-metadata">

**Author:** [@gasche](https://discuss.ocaml.org/u/gasche)\
**Replies:** 0\
**Last updated:** [October 22, 2018, 10:08am UTC](https://discuss.ocaml.org/t/finalizers-value-lifetimes-and-sys-opaque-identity/2750 "2018-10-22T10:08:15Z")

</div>

Dear discuss, I think some around here may be interested in the bugtracker thread MPR#7861 (GC collects values it shouldn’t with flambda), which is about an interaction between finalizers and optimizations that advanced…

---

## [What is my program doing when I'm not timing it?](https://discuss.ocaml.org/t/what-is-my-program-doing-when-im-not-timing-it/819)

<div class="topic-metadata">

**Author:** [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Replies:** 12\
**Last updated:** [September 8, 2017, 2:51pm UTC](https://discuss.ocaml.org/t/what-is-my-program-doing-when-im-not-timing-it/819 "2017-09-08T14:51:41Z")

</div>

I’m experimenting with different versions of the same function and testing timing with a native executable. It runs three functions, plus Core.Command.run to parse a command line parameter. I time individual function…
