feat(tvix/eval): Forbid Hash{Map,Set}, use Fx instead

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>
This commit is contained in:
Aspen Smith 2024-07-28 12:11:41 -04:00 committed by clbot
parent 1d7ba89c19
commit b8f92a6d53
17 changed files with 116 additions and 46 deletions

View file

@ -36,7 +36,7 @@ mod test_utils;
#[cfg(test)]
mod tests;
use std::collections::HashMap;
use rustc_hash::FxHashMap;
use std::path::PathBuf;
use std::rc::Rc;
use std::str::FromStr;
@ -86,7 +86,7 @@ enum BuilderGlobals {
pub struct EvaluationBuilder<'co, 'ro, 'env, IO> {
source_map: Option<SourceCode>,
globals: BuilderGlobals,
env: Option<&'env HashMap<SmolStr, Value>>,
env: Option<&'env FxHashMap<SmolStr, Value>>,
io_handle: IO,
enable_import: bool,
strict: bool,
@ -264,7 +264,7 @@ impl<'co, 'ro, 'env, IO> EvaluationBuilder<'co, 'ro, 'env, IO> {
Self { nix_path, ..self }
}
pub fn env(self, env: Option<&'env HashMap<SmolStr, Value>>) -> Self {
pub fn env(self, env: Option<&'env FxHashMap<SmolStr, Value>>) -> Self {
Self { env, ..self }
}
@ -352,7 +352,7 @@ pub struct Evaluation<'co, 'ro, 'env, IO> {
globals: Rc<GlobalsMap>,
/// Top-level variables to define in the evaluation
env: Option<&'env HashMap<SmolStr, Value>>,
env: Option<&'env FxHashMap<SmolStr, Value>>,
/// Implementation of file-IO to use during evaluation, e.g. for
/// impure builtins.
@ -570,7 +570,7 @@ fn parse_compile_internal(
location: Option<PathBuf>,
source: SourceCode,
globals: Rc<GlobalsMap>,
env: Option<&HashMap<SmolStr, Value>>,
env: Option<&FxHashMap<SmolStr, Value>>,
compiler_observer: &mut dyn CompilerObserver,
) -> Option<Rc<Lambda>> {
let parsed = rnix::ast::Root::parse(code);