From 1c377be72bcef310a696014bc45de1278a2ea4e2 Mon Sep 17 00:00:00 2001 From: razican Date: Mon, 13 Apr 2020 15:09:15 +0200 Subject: [PATCH 1/2] Added jemallocator only for Linux targets --- Cargo.lock | 75 +++++++++++++++++++++++++++++++------------ boa/Cargo.toml | 9 ++++-- boa/benches/exec.rs | 10 +++--- boa/benches/fib.rs | 16 ++++----- boa/benches/parser.rs | 11 +++---- boa/benches/string.rs | 15 +++++---- boa_cli/Cargo.toml | 5 ++- boa_cli/src/main.rs | 57 +++++++++++++++++++++++++------- 8 files changed, 136 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97df8d2eee3..35cf6063e1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ dependencies = [ "criterion", "gc", "gc_derive", + "jemallocator", "rand", "regex", "serde", @@ -60,6 +61,7 @@ name = "boa_cli" version = "0.6.0" dependencies = [ "Boa", + "jemallocator", "structopt", ] @@ -96,6 +98,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "cc" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" + [[package]] name = "cfg-if" version = "0.1.10" @@ -227,6 +235,12 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +[[package]] +name = "fs_extra" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" + [[package]] name = "gc" version = "0.3.3" @@ -266,9 +280,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.8" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" +checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" dependencies = [ "libc", ] @@ -288,6 +302,27 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +[[package]] +name = "jemalloc-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" +dependencies = [ + "cc", + "fs_extra", + "libc", +] + +[[package]] +name = "jemallocator" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" +dependencies = [ + "jemalloc-sys", + "libc", +] + [[package]] name = "js-sys" version = "0.3.37" @@ -384,9 +419,9 @@ checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" [[package]] name = "proc-macro-error" -version = "0.4.12" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7" +checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" dependencies = [ "proc-macro-error-attr", "proc-macro2", @@ -397,9 +432,9 @@ dependencies = [ [[package]] name = "proc-macro-error-attr" -version = "0.4.12" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de" +checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" dependencies = [ "proc-macro2", "quote 1.0.3", @@ -410,9 +445,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" dependencies = [ "unicode-xid 0.2.0", ] @@ -571,18 +606,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.105" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff" +checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.105" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8" +checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" dependencies = [ "proc-macro2", "quote 1.0.3", @@ -591,9 +626,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.48" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" +checksum = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9" dependencies = [ "itoa", "ryu", @@ -608,9 +643,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8faa2719539bbe9d77869bfb15d4ee769f99525e707931452c97b693b3f159d" +checksum = "ff6da2e8d107dfd7b74df5ef4d205c6aebee0706c647f6bc6a2d5789905c00fb" dependencies = [ "clap", "lazy_static", @@ -619,9 +654,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f88b8e18c69496aad6f9ddf4630dd7d585bcaf765786cb415b9aec2fe5a0430" +checksum = "a489c87c08fbaf12e386665109dd13470dcc9c4583ea3e10dd2b4523e5ebd9ac" dependencies = [ "heck", "proc-macro-error", @@ -845,9 +880,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" +checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e" dependencies = [ "winapi", ] diff --git a/boa/Cargo.toml b/boa/Cargo.toml index 2d4c7150a38..1d63d26e225 100644 --- a/boa/Cargo.toml +++ b/boa/Cargo.toml @@ -17,17 +17,20 @@ default = ["wasm-bindgen"] [dependencies] gc = "0.3.3" gc_derive = "0.3.2" -serde_json = "1.0.48" +serde_json = "1.0.51" rand = "0.7.3" regex = "1.3.6" # Optional Dependencies -wasm-bindgen = { version = "0.2.59", optional = true } -serde = { version = "1.0.105", features = ["derive"], optional = true } +wasm-bindgen = { version = "0.2.60", optional = true } +serde = { version = "1.0.106", features = ["derive"], optional = true } [dev-dependencies] criterion = "0.3.1" +[target.x86_64-unknown-linux-gnu.dev-dependencies] +jemallocator = "0.3.2" + [lib] crate-type = ["cdylib", "lib"] name = "boa" diff --git a/boa/benches/exec.rs b/boa/benches/exec.rs index 380dcffa8b5..aa98d0599d8 100644 --- a/boa/benches/exec.rs +++ b/boa/benches/exec.rs @@ -1,9 +1,9 @@ -#[macro_use] -extern crate criterion; +use boa::{exec, realm::Realm}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use boa::exec; -use boa::realm::Realm; -use criterion::{black_box, Criterion}; +#[cfg_attr(target = "x86_64-unknown-linux-gnu", global_allocator)] +#[cfg(target = "x86_64-unknown-linux-gnu")] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; static SRC: &str = r#" let a = Symbol(); diff --git a/boa/benches/fib.rs b/boa/benches/fib.rs index 09af95c222f..508d5360af8 100644 --- a/boa/benches/fib.rs +++ b/boa/benches/fib.rs @@ -1,9 +1,9 @@ -#[macro_use] -extern crate criterion; - use boa::exec; -use criterion::black_box; -use criterion::Criterion; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +#[cfg_attr(target = "x86_64-unknown-linux-gnu", global_allocator)] +#[cfg(target = "x86_64-unknown-linux-gnu")] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; static SRC: &str = r#" let num = 12; @@ -19,9 +19,9 @@ res; "#; fn fibonacci(c: &mut Criterion) { - c.bench_function("fibonacci (Execution)", move |b| { - b.iter(|| exec(black_box(SRC))) - }); + c.bench_function("fibonacci (Execution)", move |b| { + b.iter(|| exec(black_box(SRC))) + }); } criterion_group!(benches, fibonacci); diff --git a/boa/benches/parser.rs b/boa/benches/parser.rs index 5c697a174ec..4826f4dbd1c 100644 --- a/boa/benches/parser.rs +++ b/boa/benches/parser.rs @@ -1,10 +1,9 @@ -#[macro_use] -extern crate criterion; +use boa::syntax::{lexer::Lexer, parser::Parser}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use boa::syntax::lexer::Lexer; -use boa::syntax::parser::Parser; -use criterion::black_box; -use criterion::Criterion; +#[cfg_attr(target = "x86_64-unknown-linux-gnu", global_allocator)] +#[cfg(target = "x86_64-unknown-linux-gnu")] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; static EXPRESSION: &str = r#" 1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; diff --git a/boa/benches/string.rs b/boa/benches/string.rs index 2a7b275a299..715858c445c 100644 --- a/boa/benches/string.rs +++ b/boa/benches/string.rs @@ -1,11 +1,12 @@ -#[macro_use] -extern crate criterion; +use boa::{ + exec, + syntax::{lexer::Lexer, parser::Parser}, +}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use boa::exec; -use boa::syntax::lexer::Lexer; -use boa::syntax::parser::Parser; -use criterion::black_box; -use criterion::Criterion; +#[cfg_attr(target = "x86_64-unknown-linux-gnu", global_allocator)] +#[cfg(target = "x86_64-unknown-linux-gnu")] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; static SRC: &str = "let foo = 'hello world!'; foo;"; diff --git a/boa_cli/Cargo.toml b/boa_cli/Cargo.toml index abd015bcee6..b47d9e2cb62 100644 --- a/boa_cli/Cargo.toml +++ b/boa_cli/Cargo.toml @@ -12,4 +12,7 @@ edition = "2018" [dependencies] Boa = { path = "../boa", features = ["serde-ast"], default-features = false } -structopt = "0.3.12" +structopt = "0.3.13" + +[target.x86_64-unknown-linux-gnu.dependencies] +jemallocator = "0.3.2" diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 38741d591d0..3dbad988206 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -1,15 +1,48 @@ -#![deny(unused_qualifications, clippy::correctness, clippy::style)] -#![warn(clippy::perf)] -#![allow(clippy::cognitive_complexity)] - -use boa::builtins::console::log; -use boa::serde_json; -use boa::syntax::ast::{node::Node, token::Token}; -use boa::{exec::Executor, forward_val, realm::Realm}; -use std::io::{self, Write}; -use std::{fs::read_to_string, path::PathBuf}; -use structopt::clap::arg_enum; -use structopt::StructOpt; +#![deny( + unused_qualifications, + clippy::all, + unused_qualifications, + unused_import_braces, + unused_lifetimes, + unreachable_pub, + trivial_numeric_casts, + rustdoc, + missing_debug_implementations, + missing_copy_implementations, + deprecated_in_future, + non_ascii_idents, + rust_2018_compatibility, + rust_2018_idioms, + future_incompatible, + nonstandard_style +)] +#![warn(clippy::perf, clippy::single_match_else, clippy::dbg_macro)] +#![allow( + clippy::missing_inline_in_public_items, + clippy::cognitive_complexity, + clippy::must_use_candidate, + clippy::missing_errors_doc, + clippy::as_conversions +)] + +use boa::{ + builtins::console::log, + exec::Executor, + forward_val, + realm::Realm, + serde_json, + syntax::ast::{node::Node, token::Token}, +}; +use std::{ + fs::read_to_string, + io::{self, Write}, + path::PathBuf, +}; +use structopt::{clap::arg_enum, StructOpt}; + +#[cfg_attr(target = "x86_64-unknown-linux-gnu", global_allocator)] +#[cfg(target = "x86_64-unknown-linux-gnu")] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; /// CLI configuration for Boa. // From 02cfe9e97b0965d1f8da83f68294769c7dd4b50b Mon Sep 17 00:00:00 2001 From: razican Date: Mon, 13 Apr 2020 15:31:32 +0200 Subject: [PATCH 2/2] Fixed formatting --- boa/benches/fib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boa/benches/fib.rs b/boa/benches/fib.rs index 508d5360af8..3b10c8dd50d 100644 --- a/boa/benches/fib.rs +++ b/boa/benches/fib.rs @@ -19,9 +19,9 @@ res; "#; fn fibonacci(c: &mut Criterion) { - c.bench_function("fibonacci (Execution)", move |b| { - b.iter(|| exec(black_box(SRC))) - }); + c.bench_function("fibonacci (Execution)", move |b| { + b.iter(|| exec(black_box(SRC))) + }); } criterion_group!(benches, fibonacci);