diff --git a/.gitignore b/.gitignore index a285de586d2..d85a95bc985 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ chrome_profiler.json # e2e test playwright-report test-results + +# dhat +dhat-*.json \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 6186ce14411..5138c658080 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,6 +342,7 @@ dependencies = [ "boa_runtime", "clap", "colored", + "dhat", "jemallocator", "phf", "pollster", @@ -955,6 +956,22 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "dhat" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2aaf837aaf456f6706cb46386ba8dffd4013a757e36f4ea05c20dd46b209a3" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot 0.12.1", + "rustc-hash", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "displaydoc" version = "0.2.4" @@ -1883,6 +1900,16 @@ dependencies = [ "adler", ] +[[package]] +name = "mintex" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7c5ba1c3b5a23418d7bbf98c71c3d4946a0125002129231da8d6b723d559cb" +dependencies = [ + "once_cell", + "sys-info", +] + [[package]] name = "mio" version = "0.8.8" @@ -2838,6 +2865,16 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "sys-info" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "sys-locale" version = "0.3.1" @@ -2899,6 +2936,12 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "thread_local" version = "1.1.7" diff --git a/Cargo.toml b/Cargo.toml index 6f7bc27690a..46dca258247 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,6 +100,7 @@ incremental = false lto = "fat" # Makes sure that all code is compiled together, for LTO codegen-units = 1 +debug = 1 # The test profile, used for `cargo test`. [profile.test] diff --git a/boa_cli/Cargo.toml b/boa_cli/Cargo.toml index 6d30aa0164f..33d81dee094 100644 --- a/boa_cli/Cargo.toml +++ b/boa_cli/Cargo.toml @@ -25,9 +25,11 @@ colored.workspace = true regex.workspace = true phf = { workspace = true, features = ["macros"] } pollster.workspace = true +dhat = { version = "0.3.2", optional = true } [features] default = ["boa_engine/annex-b", "boa_engine/experimental", "boa_engine/intl"] +dhat = ["dep:dhat"] [target.x86_64-unknown-linux-gnu.dependencies] jemallocator.workspace = true diff --git a/boa_cli/src/main.rs b/boa_cli/src/main.rs index 8e8f964aa31..3c313e4ffde 100644 --- a/boa_cli/src/main.rs +++ b/boa_cli/src/main.rs @@ -88,13 +88,22 @@ use std::{ println, }; -#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] +#[cfg(all( + target_arch = "x86_64", + target_os = "linux", + target_env = "gnu", + not(feature = "dhat") +))] #[cfg_attr( all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"), global_allocator )] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; +#[cfg(feature = "dhat")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + /// CLI configuration for Boa. static CLI_HISTORY: &str = ".boa_history"; @@ -367,6 +376,9 @@ fn evaluate_files( } fn main() -> Result<(), io::Error> { + #[cfg(feature = "dhat")] + let _profiler = dhat::Profiler::new_heap(); + let args = Opt::parse(); let queue: &dyn JobQueue = &Jobs::default(); diff --git a/boa_engine/src/context/intrinsics.rs b/boa_engine/src/context/intrinsics.rs index 87768a22e9d..2547dea121c 100644 --- a/boa_engine/src/context/intrinsics.rs +++ b/boa_engine/src/context/intrinsics.rs @@ -191,7 +191,7 @@ impl Default for StandardConstructors { )), string: StandardConstructor::with_prototype(JsObject::from_proto_and_data( None, - ObjectData::string("".into()), + ObjectData::string(js_string!()), )), regexp: StandardConstructor::default(), symbol: StandardConstructor::default(), diff --git a/boa_engine/src/string/common.rs b/boa_engine/src/string/common.rs index 1b49483f4c0..8e8b05febee 100644 --- a/boa_engine/src/string/common.rs +++ b/boa_engine/src/string/common.rs @@ -193,9 +193,6 @@ thread_local! { } /// Array of raw static strings that aren't reference counted. -/// -/// The macro `static_strings` automatically sorts the array of strings, making it faster -/// for searches by using `binary_search`. const RAW_STATICS: &[&[u16]] = &[ utf16!(""), // Well known symbols