diff options
author | Aspen Smith <root@gws.fyi> | 2024-07-28T16·11-0400 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-08-07T12·38+0000 |
commit | b8f92a6d535af09c24ac887855eb230ca25af1ed (patch) | |
tree | 82cea6a4d3979e0c48e9f97285b8564a24e9ceb0 /tvix/cli | |
parent | 1d7ba89c19b231898a997f1af3c13ed8c7247793 (diff) |
feat(tvix/eval): Forbid Hash{Map,Set}, use Fx instead r/8453
Per https://nnethercote.github.io/perf-book/hashing.html, we have basically no reason to use the default hasher over a faster, non-DoS-resistant hasher. This gives a nice perf boost basically for free: hello outpath time: [704.76 ms 714.91 ms 725.63 ms] change: [-7.2391% -6.1018% -4.9189%] (p = 0.00 < 0.05) Performance has improved. Change-Id: If5587f444ed3af69f8af4eead6af3ea303b4ae68 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12046 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: Ilan Joselevich <personal@ilanjoselevich.com> Autosubmit: aspen <root@gws.fyi>
Diffstat (limited to 'tvix/cli')
-rw-r--r-- | tvix/cli/Cargo.toml | 1 | ||||
-rw-r--r-- | tvix/cli/src/lib.rs | 8 | ||||
-rw-r--r-- | tvix/cli/src/repl.rs | 7 |
3 files changed, 10 insertions, 6 deletions
diff --git a/tvix/cli/Cargo.toml b/tvix/cli/Cargo.toml index abbb7e6c2bd0..7f93da85d47a 100644 --- a/tvix/cli/Cargo.toml +++ b/tvix/cli/Cargo.toml @@ -26,6 +26,7 @@ thiserror = "1.0.38" tokio = "1.28.0" tracing = "0.1.40" tracing-indicatif = "0.3.6" +rustc-hash = "2.0.0" [dependencies.wu-manber] git = "https://github.com/tvlfyi/wu-manber.git" diff --git a/tvix/cli/src/lib.rs b/tvix/cli/src/lib.rs index 7686cc2c0fe8..2351da13a771 100644 --- a/tvix/cli/src/lib.rs +++ b/tvix/cli/src/lib.rs @@ -1,5 +1,7 @@ -use std::{collections::HashMap, path::PathBuf, rc::Rc}; +use std::path::PathBuf; +use std::rc::Rc; +use rustc_hash::FxHashMap; use smol_str::SmolStr; use std::fmt::Write; use tracing::{instrument, Span}; @@ -86,7 +88,7 @@ pub fn evaluate( path: Option<PathBuf>, args: &Args, allow_incomplete: AllowIncomplete, - env: Option<&HashMap<SmolStr, Value>>, + env: Option<&FxHashMap<SmolStr, Value>>, globals: Option<Rc<GlobalsMap>>, source_map: Option<SourceCode>, ) -> Result<EvalResult, IncompleteInput> { @@ -218,7 +220,7 @@ pub fn interpret( args: &Args, explain: bool, allow_incomplete: AllowIncomplete, - env: Option<&HashMap<SmolStr, Value>>, + env: Option<&FxHashMap<SmolStr, Value>>, globals: Option<Rc<GlobalsMap>>, source_map: Option<SourceCode>, ) -> Result<InterpretResult, IncompleteInput> { diff --git a/tvix/cli/src/repl.rs b/tvix/cli/src/repl.rs index 601b639154a6..e4b499609829 100644 --- a/tvix/cli/src/repl.rs +++ b/tvix/cli/src/repl.rs @@ -1,6 +1,7 @@ +use std::path::PathBuf; use std::rc::Rc; -use std::{collections::HashMap, path::PathBuf}; +use rustc_hash::FxHashMap; use rustyline::{error::ReadlineError, Editor}; use smol_str::SmolStr; use tvix_eval::{GlobalsMap, SourceCode, Value}; @@ -88,7 +89,7 @@ pub struct Repl<'a> { multiline_input: Option<String>, rl: Editor<()>, /// Local variables defined at the top-level in the repl - env: HashMap<SmolStr, Value>, + env: FxHashMap<SmolStr, Value>, io_handle: Rc<TvixStoreIO>, args: &'a Args, @@ -102,7 +103,7 @@ impl<'a> Repl<'a> { Self { multiline_input: None, rl, - env: HashMap::new(), + env: FxHashMap::default(), io_handle, args, source_map: Default::default(), |