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:
commit
88f0fdce6f
4 changed files with 12 additions and 7 deletions
|
@ -25,6 +25,7 @@ expose-test-schema = []
|
||||||
default = ["chrono", "url", "uuid"]
|
default = ["chrono", "url", "uuid"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
fnv = "1.0.3"
|
||||||
chrono = { version = "^0.4.0", optional = true }
|
chrono = { version = "^0.4.0", optional = true }
|
||||||
ordermap = { version = "^0.2.11", features = ["serde-1"] }
|
ordermap = { version = "^0.2.11", features = ["serde-1"] }
|
||||||
serde = { version = "^1.0.8" }
|
serde = { version = "^1.0.8" }
|
||||||
|
|
|
@ -4,6 +4,8 @@ use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
|
use fnv::FnvHashMap;
|
||||||
|
|
||||||
use GraphQLError;
|
use GraphQLError;
|
||||||
use ast::{Definition, Document, Fragment, FromInputValue, InputValue, OperationType, Selection,
|
use ast::{Definition, Document, Fragment, FromInputValue, InputValue, OperationType, Selection,
|
||||||
ToInputValue, Type};
|
ToInputValue, Type};
|
||||||
|
@ -24,7 +26,7 @@ use types::name::Name;
|
||||||
/// into `Type` instances and automatically registers them.
|
/// into `Type` instances and automatically registers them.
|
||||||
pub struct Registry<'r> {
|
pub struct Registry<'r> {
|
||||||
/// Currently registered types
|
/// Currently registered types
|
||||||
pub types: HashMap<Name, MetaType<'r>>,
|
pub types: FnvHashMap<Name, MetaType<'r>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -519,7 +521,7 @@ where
|
||||||
|
|
||||||
impl<'r> Registry<'r> {
|
impl<'r> Registry<'r> {
|
||||||
/// Construct a new registry
|
/// 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 }
|
Registry { types: types }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,7 @@ extern crate serde_derive;
|
||||||
#[cfg(any(test, feature = "expose-test-schema"))]
|
#[cfg(any(test, feature = "expose-test-schema"))]
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
|
extern crate fnv;
|
||||||
extern crate ordermap;
|
extern crate ordermap;
|
||||||
|
|
||||||
#[cfg(any(test, feature = "chrono"))]
|
#[cfg(any(test, feature = "chrono"))]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use fnv::FnvHashMap;
|
||||||
|
|
||||||
use types::base::GraphQLType;
|
use types::base::GraphQLType;
|
||||||
use types::name::Name;
|
use types::name::Name;
|
||||||
use executor::{Context, Registry};
|
use executor::{Context, Registry};
|
||||||
|
@ -26,10 +27,10 @@ pub struct RootNode<'a, QueryT: GraphQLType, MutationT: GraphQLType> {
|
||||||
|
|
||||||
/// Metadata for a schema
|
/// Metadata for a schema
|
||||||
pub struct SchemaType<'a> {
|
pub struct SchemaType<'a> {
|
||||||
types: HashMap<Name, MetaType<'a>>,
|
types: FnvHashMap<Name, MetaType<'a>>,
|
||||||
query_type_name: String,
|
query_type_name: String,
|
||||||
mutation_type_name: Option<String>,
|
mutation_type_name: Option<String>,
|
||||||
directives: HashMap<String, DirectiveType<'a>>,
|
directives: FnvHashMap<String, DirectiveType<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Context for SchemaType<'a> {}
|
impl<'a> Context for SchemaType<'a> {}
|
||||||
|
@ -104,11 +105,11 @@ impl<'a> SchemaType<'a> {
|
||||||
QueryT: GraphQLType,
|
QueryT: GraphQLType,
|
||||||
MutationT: GraphQLType,
|
MutationT: GraphQLType,
|
||||||
{
|
{
|
||||||
let mut directives = HashMap::new();
|
let mut directives = FnvHashMap::default();
|
||||||
let query_type_name: String;
|
let query_type_name: String;
|
||||||
let mutation_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
|
query_type_name = registry
|
||||||
.get_type::<QueryT>(query_info)
|
.get_type::<QueryT>(query_info)
|
||||||
.innermost_name()
|
.innermost_name()
|
||||||
|
|
Loading…
Reference in a new issue