Do not export global allocator (#533)

* Do not export allocator

* Make sure to use jemalloc in all downstream tests

* Update readme

* Remove test jemalloc boilerplate

* One more

* Fix clippies

* One more

* Clippy

Co-authored-by: Daniel Lubarov <daniel@lubarov.com>
This commit is contained in:
Remco Bloemen 2022-05-03 13:16:53 -07:00 committed by GitHub
parent 90f6d07f72
commit 7769c269bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 43 additions and 12 deletions

View File

@ -31,7 +31,15 @@ RUSTFLAGS=-Ctarget-cpu=native cargo run --release --example bench_recursion -- -
## Jemalloc
By default, Plonky2 uses the [Jemalloc](http://jemalloc.net) memory allocator due to its superior performance. Currently, it changes the default allocator of any binary to which it is linked. You can disable this behavior by removing the corresponding lines in [`plonky2/src/lib.rs`](https://github.com/mir-protocol/plonky2/blob/main/plonky2/src/lib.rs).
Plonky2 prefers the [Jemalloc](http://jemalloc.net) memory allocator due to its superior performance. To use it, include `jemallocator = "0.3.2"` in`Cargo.toml`and add the following lines
to your `main.rs`:
```rust
use jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
```
Jemalloc is known to cause crashes when a binary compiled for x86 is run on an Apple silicon-based Mac under [Rosetta 2](https://support.apple.com/en-us/HT211861). If you are experiencing crashes on your Apple silicon Mac, run `rustc --print target-libdir`. The output should contain `aarch64-apple-darwin`. If the output contains `x86_64-apple-darwin`, then you are running the Rust toolchain for x86; we recommend switching to the native ARM version.

View File

@ -27,15 +27,15 @@ serde_cbor = "0.11.1"
keccak-hash = "0.8.0"
static_assertions = "1.1.0"
[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.3.2"
[dev-dependencies]
criterion = "0.3.5"
tynm = "0.1.6"
structopt = "0.3.26"
num_cpus = "1.13.1"
[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
jemallocator = "0.3.2"
[[bench]]
name = "field_arithmetic"
harness = false

View File

@ -0,0 +1,7 @@
// Set up Jemalloc
#[cfg(not(target_env = "msvc"))]
use jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

View File

@ -1,3 +1,5 @@
mod allocator;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use plonky2::field::field_types::Field;
use plonky2::field::goldilocks_field::GoldilocksField;

View File

@ -1,3 +1,5 @@
mod allocator;
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use plonky2::field::extension_field::quadratic::QuadraticExtension;
use plonky2::field::extension_field::quartic::QuarticExtension;

View File

@ -1,6 +1,8 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
mod allocator;
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::hash::hash_types::{BytesHash, RichField};

View File

@ -1,5 +1,7 @@
#![feature(generic_const_exprs)]
mod allocator;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::hash::hash_types::RichField;

View File

@ -1,3 +1,5 @@
mod allocator;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use plonky2::field::field_types::Field;
use plonky2::field::goldilocks_field::GoldilocksField;

View File

@ -1,3 +1,5 @@
mod allocator;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use plonky2::field::field_types::Field;
use plonky2::field::goldilocks_field::GoldilocksField;

View File

@ -19,11 +19,3 @@ pub mod hash;
pub mod iop;
pub mod plonk;
pub mod util;
// Set up Jemalloc
#[cfg(not(target_env = "msvc"))]
use jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

View File

@ -21,3 +21,6 @@ criterion = "0.3.5"
[[bench]]
name = "lookup_permuted_cols"
harness = false
[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
jemallocator = "0.3.2"

View File

@ -0,0 +1,7 @@
// Set up Jemalloc
#[cfg(not(target_env = "msvc"))]
use jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;

View File

@ -1,3 +1,5 @@
mod allocator;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use itertools::Itertools;
use plonky2::field::field_types::Field;