Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Merge #602
Browse files Browse the repository at this point in the history
602: Use mimalloc as the default allocator r=Kerollmops a=loiclec

## What does this PR do?
Use mimalloc as the global allocator for milli's benchmarks on macOS.

## Why?
On Linux, we use jemalloc, which is a very fast allocator. But on macOS, we currently use the system allocator, which is very slow. In practice, this difference in allocator speed means that it is difficult to gain insight into milli's performance by running benchmarks locally on the Mac.

By using mimalloc, which is another excellent allocator, we reduce the speed difference between the two platforms.

Co-authored-by: Loïc Lecrenier <loic@meilisearch.com>
  • Loading branch information
bors[bot] and Loïc Lecrenier authored Aug 17, 2022
2 parents f55034e + 5d59bfd commit cd2635c
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 51 deletions.
12 changes: 5 additions & 7 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@ edition = "2018"
publish = false

[dependencies]
milli = { path = "../milli" }
anyhow = "1.0.56"
serde_json = { version = "1.0.79", features = ["preserve_order"] }
csv = "1.1.6"

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = "0.3.2"
milli = { path = "../milli" }
mimalloc = { version = "0.1.29", default-features = false }
serde_json = { version = "1.0.79", features = ["preserve_order"] }

[dev-dependencies]
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1" }
criterion = { version = "0.3.5", features = ["html_reports"] }
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1" }
rand = "0.8.5"
rand_chacha = "0.3.1"
roaring = "0.9.0"

[build-dependencies]
anyhow = "1.0.56"
bytes = "1.1.0"
flate2 = "1.0.22"
convert_case = "0.5.0"
flate2 = "1.0.22"
reqwest = { version = "0.11.9", features = ["blocking", "rustls-tls"], default-features = false }

[[bench]]
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/benches/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use criterion::{criterion_group, criterion_main};
use milli::tokenizer::TokenizerBuilder;
use milli::{FormatOptions, MatcherBuilder, MatchingWord, MatchingWords};

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

struct Conf<'a> {
name: &'a str,
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/benches/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use rand::seq::SliceRandom;
use rand_chacha::rand_core::SeedableRng;
use roaring::RoaringBitmap;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

const BENCHMARK_ITERATION: usize = 10;

Expand Down
3 changes: 1 addition & 2 deletions benchmarks/benches/search_geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use criterion::{criterion_group, criterion_main};
use milli::update::Settings;
use utils::Conf;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

fn base_conf(builder: &mut Settings) {
let displayed_fields =
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/benches/search_songs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use criterion::{criterion_group, criterion_main};
use milli::update::Settings;
use utils::Conf;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

fn base_conf(builder: &mut Settings) {
let displayed_fields =
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/benches/search_wiki.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use criterion::{criterion_group, criterion_main};
use milli::update::Settings;
use utils::Conf;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

fn base_conf(builder: &mut Settings) {
let displayed_fields = ["title", "body", "url"].iter().map(|s| s.to_string()).collect();
Expand Down
20 changes: 9 additions & 11 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ description = "A CLI to interact with a milli index"
publish = false

[dependencies]
bimap = "0.6.2"
byte-unit = { version = "4.0.14", features = ["serde"] }
color-eyre = "0.6.1"
csv = "1.1.6"
eyre = "0.6.7"
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1", default-features = false, features = ["lmdb", "sync-read-txn"] }
indicatif = "0.16.2"
milli = { path = "../milli" }
mimalloc = { version = "0.1.29", default-features = false }
serde = "1.0.136"
serde_json = "1.0.79"
structopt = "0.3.26"
milli = { path = "../milli" }
eyre = "0.6.7"
color-eyre = "0.6.1"
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1", default-features = false, features = ["lmdb", "sync-read-txn"] }
byte-unit = { version = "4.0.14", features = ["serde"] }
bimap = "0.6.2"
csv = "1.1.6"
stderrlog = "0.5.1"

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = "0.3.2"
structopt = "0.3.26"
3 changes: 1 addition & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use milli::update::{self, IndexDocumentsConfig, IndexDocumentsMethod, IndexerCon
use milli::{Index, Object};
use structopt::StructOpt;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[derive(Debug, StructOpt)]
#[structopt(name = "Milli CLI", about = "A simple CLI to manipulate a milli index.")]
Expand Down
4 changes: 1 addition & 3 deletions helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ anyhow = "1.0.56"
byte-unit = { version = "4.0.14", default-features = false, features = ["std"] }
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1" }
milli = { path = "../milli" }
mimalloc = { version = "0.1.29", default-features = false }
stderrlog = "0.5.1"
structopt = { version = "0.3.26", default-features = false }

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = "0.3.2"
3 changes: 1 addition & 2 deletions helpers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use heed::{CompactionOption, Env, EnvOpenOptions};
use structopt::StructOpt;
use Command::*;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[derive(Debug, StructOpt)]
/// Some helpers commands for milli.
Expand Down
7 changes: 3 additions & 4 deletions http-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crossbeam-channel = "0.5.2"
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1" }
memmap2 = "0.5.3"
milli = { path = "../milli" }
mimalloc = { version = "0.1.29", default-features = false }
once_cell = "1.10.0"
rayon = "1.5.1"
structopt = { version = "0.3.26", default-features = false, features = ["wrap_help"] }
Expand All @@ -32,18 +33,16 @@ tokio-stream = { version = "0.1.8", default-features = false, features = ["sync"
warp = "0.3.2"

# logging
fst = "0.4.7"
log = "0.4.14"
stderrlog = "0.5.1"
fst = "0.4.7"

# Temporary fix for bitvec, remove once fixed. (https://github.com/bitvecto-rs/bitvec/issues/105)
funty = "2.0.0"
bimap = "0.6.2"
csv = "1.1.6"
funty = "2.0.0"

[dev-dependencies]
maplit = "1.0.2"
serde_test = "1.0.136"

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = "0.3.2"
3 changes: 1 addition & 2 deletions http-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ use warp::Filter;

use self::update_store::UpdateStore;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

static GLOBAL_CONFIG: OnceCell<IndexerConfig> = OnceCell::new();

Expand Down
4 changes: 1 addition & 3 deletions infos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ byte-unit = { version = "4.0.14", default-features = false, features = ["std"] }
csv = "1.1.6"
heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.1" }
milli = { path = "../milli" }
mimalloc = { version = "0.1.29", default-features = false }
roaring = "0.9.0"
serde_json = "1.0.79"
stderrlog = "0.5.1"
structopt = { version = "0.3.26", default-features = false }

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = "0.3.2"
3 changes: 1 addition & 2 deletions infos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use milli::{FieldId, Index};
use structopt::StructOpt;
use Command::*;

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

const ALL_DATABASE_NAMES: &[&str] = &[
MAIN,
Expand Down
4 changes: 1 addition & 3 deletions milli/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ serde_json = { version = "1.0.62", features = ["preserve_order"] }
anyhow = "1.0"
tempfile = "3.3"
arbitrary-json = "0.1.0"

[target.'cfg(target_os = "linux")'.dependencies]
jemallocator = "0.3.2"
mimalloc = { version = "0.1.29", default-features = false }

[dependencies.milli]
path = ".."
Expand Down
3 changes: 1 addition & 2 deletions milli/fuzz/fuzz_targets/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ use milli::update::{IndexDocuments, IndexDocumentsConfig, IndexerConfig, Setting
use milli::Index;
use serde_json::{Map, Value};

#[cfg(target_os = "linux")]
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

/// reads json from input and write an obkv batch to writer.
pub fn read_json(input: impl Read, writer: impl Write + Seek) -> Result<usize> {
Expand Down

0 comments on commit cd2635c

Please sign in to comment.