Merge pull request #93 from srijs/perf/schema-fnv-hash-map

perf(schema): use FnvHashMap for type and directive names
This commit is contained in:
Magnus Hallin 2017-10-08 09:54:22 +02:00 committed by GitHub
commit 88f0fdce6f
4 changed files with 12 additions and 7 deletions

View file

@ -25,6 +25,7 @@ expose-test-schema = []
default = ["chrono", "url", "uuid"]
[dependencies]
fnv = "1.0.3"
chrono = { version = "^0.4.0", optional = true }
ordermap = { version = "^0.2.11", features = ["serde-1"] }
serde = { version = "^1.0.8" }

View file

@ -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<Name, MetaType<'r>>,
pub types: FnvHashMap<Name, MetaType<'r>>,
}
#[derive(Clone)]
@ -519,7 +521,7 @@ where
impl<'r> Registry<'r> {
/// Construct a new registry
pub fn new(types: HashMap<Name, MetaType<'r>>) -> Registry<'r> {
pub fn new(types: FnvHashMap<Name, MetaType<'r>>) -> Registry<'r> {
Registry { types: types }
}

View file

@ -127,6 +127,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 = "chrono"))]

View file

@ -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<Name, MetaType<'a>>,
types: FnvHashMap<Name, MetaType<'a>>,
query_type_name: String,
mutation_type_name: Option<String>,
directives: HashMap<String, DirectiveType<'a>>,
directives: FnvHashMap<String, DirectiveType<'a>>,
}
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::<QueryT>(query_info)
.innermost_name()