# Comparing OCaml's best-fit and next-fit memory allocators

DevFeed: [Comparing OCaml's best-fit and next-fit memory allocators](<https://devfeed.tech/articles/memory-allocator-showdown-20194.md>)

Original publisher: [Read original article](<https://blog.janestreet.com/memory-allocator-showdown/>)

Author: Stephen Dolan

Published: 2020-09-15T00:00:00Z

Content type: article

Language: en

Sources: [Jane Street](<https://devfeed.tech/sources/jane-street.md>)

Topics: [OCaml](<https://devfeed.tech/topics/ocaml.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [garbage-collection](<https://devfeed.tech/tags/garbage-collection.md>), [gc](<https://devfeed.tech/tags/gc.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [performance](<https://devfeed.tech/tags/performance.md>)

## AI overview

This article examines how to compare OCaml's best-fit and next-fit memory allocators in a garbage-collected system. Benchmarks show that best-fit can trade slightly slower execution for lower memory use, and that varying garbage-collection settings reveals a broader space-time performance trade-off.

## Source excerpt

Since version 4.10, OCaml offers a new best-fit memory allocator alongside its existing default, the next-fit allocator. At Jane Street, we've seen a big improvement after switching over to the new allocator. This post isn't about how the new allocator works. For that, the best source is these notes from a talk by its author. Instead, this post is about just how tricky it is to compare two allocators in a reasonable way, especially for a garbage-collected system.