From bcb594edc1a91bb7df9a29a71737938e70ad2f0b Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Mon, 2 Oct 2017 19:07:09 +1100 Subject: [PATCH] perf(schema): use FnvHashMap for type and directive names --- juniper/Cargo.toml | 1 + juniper/src/executor.rs | 6 ++++-- juniper/src/lib.rs | 1 + juniper/src/schema/model.rs | 11 ++++++----- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 66a796a7..dbe03a48 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -25,6 +25,7 @@ expose-test-schema = [] default = ["url", "uuid"] [dependencies] +fnv = "1.0.3" ordermap = { version = "^0.2.11", features = ["serde-1"] } serde = { version = "^1.0.8" } serde_derive = {version="^1.0.8" } diff --git a/juniper/src/executor.rs b/juniper/src/executor.rs index 7ebca38f..9b95217d 100644 --- a/juniper/src/executor.rs +++ b/juniper/src/executor.rs @@ -4,6 +4,8 @@ use std::borrow::Cow; use std::collections::HashMap; use std::sync::RwLock; +use fnv::FnvHashMap; + use GraphQLError; use ast::{Definition, Document, Fragment, FromInputValue, InputValue, OperationType, Selection, ToInputValue, Type}; @@ -24,7 +26,7 @@ use types::name::Name; /// into `Type` instances and automatically registers them. pub struct Registry<'r> { /// Currently registered types - pub types: HashMap>, + pub types: FnvHashMap>, } #[derive(Clone)] @@ -519,7 +521,7 @@ where impl<'r> Registry<'r> { /// Construct a new registry - pub fn new(types: HashMap>) -> Registry<'r> { + pub fn new(types: FnvHashMap>) -> Registry<'r> { Registry { types: types } } diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index 9a98e345..86b67b42 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -122,6 +122,7 @@ extern crate serde_derive; #[cfg(any(test, feature = "expose-test-schema"))] extern crate serde_json; +extern crate fnv; extern crate ordermap; #[cfg(any(test, feature = "url"))] diff --git a/juniper/src/schema/model.rs b/juniper/src/schema/model.rs index 2515b151..41fe51eb 100644 --- a/juniper/src/schema/model.rs +++ b/juniper/src/schema/model.rs @@ -1,6 +1,7 @@ -use std::collections::HashMap; use std::fmt; +use fnv::FnvHashMap; + use types::base::GraphQLType; use types::name::Name; use executor::{Context, Registry}; @@ -26,10 +27,10 @@ pub struct RootNode<'a, QueryT: GraphQLType, MutationT: GraphQLType> { /// Metadata for a schema pub struct SchemaType<'a> { - types: HashMap>, + types: FnvHashMap>, query_type_name: String, mutation_type_name: Option, - directives: HashMap>, + directives: FnvHashMap>, } impl<'a> Context for SchemaType<'a> {} @@ -104,11 +105,11 @@ impl<'a> SchemaType<'a> { QueryT: GraphQLType, MutationT: GraphQLType, { - let mut directives = HashMap::new(); + let mut directives = FnvHashMap::default(); let query_type_name: String; let mutation_type_name: String; - let mut registry = Registry::new(HashMap::new()); + let mut registry = Registry::new(FnvHashMap::default()); query_type_name = registry .get_type::(query_info) .innermost_name()