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

@ -9,8 +9,8 @@ use genawaiter::rc::Gen;
use imbl::OrdMap;
use regex::Regex;
use std::cmp::{self, Ordering};
use std::collections::BTreeMap;
use std::collections::VecDeque;
use std::collections::{BTreeMap, HashSet};
use std::path::PathBuf;
use crate::arithmetic_op;
@ -88,6 +88,7 @@ mod pure_builtins {
use imbl::Vector;
use itertools::Itertools;
use os_str_bytes::OsStringBytes;
use rustc_hash::FxHashSet;
use crate::{value::PointerEquality, AddContext, NixContext, NixContextElement};
@ -700,7 +701,7 @@ mod pure_builtins {
//
// In this implementation, we do none of that, no syntax checks, no realization.
// The next `TODO` are the checks that Nix implements.
let mut ctx_elements: HashSet<NixContextElement> = HashSet::new();
let mut ctx_elements: FxHashSet<NixContextElement> = FxHashSet::default();
let span = generators::request_span(&co).await;
let origin = origin
.coerce_to_string(
@ -1115,7 +1116,7 @@ mod pure_builtins {
.to_list()?
.into_iter()
.map(|v| v.to_str())
.collect::<Result<HashSet<_>, _>>()?;
.collect::<Result<FxHashSet<_>, _>>()?;
let res = attrs.iter().filter_map(|(k, v)| {
if !keys.contains(k) {
Some((k.clone(), v.clone()))